-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commiton issue #3061 Injecting mermaid utilities in registered diagram
- Loading branch information
Showing
15 changed files
with
197 additions
and
77 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const warning = (s: string) => { | ||
// Todo remove debug code | ||
console.error('Log function was called before initialization', s); // eslint-disable-line | ||
}; | ||
|
||
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'; | ||
|
||
export const LEVELS: Record<LogLevel, number> = { | ||
trace: 0, | ||
debug: 1, | ||
info: 2, | ||
warn: 3, | ||
error: 4, | ||
fatal: 5, | ||
}; | ||
|
||
export const log: Record<keyof typeof LEVELS, typeof console.log> = { | ||
trace: warning, | ||
debug: warning, | ||
info: warning, | ||
warn: warning, | ||
error: warning, | ||
fatal: warning, | ||
}; | ||
|
||
export let setLogLevel: (level: keyof typeof LEVELS | number | string) => void; | ||
export let getConfig: () => object; | ||
export let sanitizeText: (str: string) => string; | ||
// eslint-disable @typescript-eslint/no-explicit-any | ||
export let setupGraphViewbox: ( | ||
graph: any, | ||
svgElem: any, | ||
padding: any, | ||
useMaxWidth: boolean | ||
) => void; | ||
|
||
export const injectUtils = ( | ||
_log: Record<keyof typeof LEVELS, typeof console.log>, | ||
_setLogLevel: any, | ||
_getConfig: any, | ||
_sanitizeText: any, | ||
_setupGraphViewbox: any | ||
) => { | ||
log.debug = _log.debug; | ||
log.info = _log.info; | ||
log.warn = _log.warn; | ||
log.error = _log.error; | ||
setLogLevel = _setLogLevel; | ||
getConfig = _getConfig; | ||
sanitizeText = _sanitizeText; | ||
setupGraphViewbox = _setupGraphViewbox; | ||
}; | ||
|
||
/* | ||
const warning = (..._args: any[]) => { | ||
console.error('Log function was called before initialization'); | ||
}; | ||
export let log = { | ||
trace: warning, | ||
debug: warning, | ||
info: warning, | ||
warn: warning, | ||
error: warning, | ||
fatal: warning, | ||
}; | ||
export let setLogLevel; | ||
export let getConfig; | ||
export let sanitizeText; | ||
export let setupGraphViewbox; | ||
export const injectUtils = (_log, _setLogLevel, _getConfig, _sanitizeText, _setupGraphViewbox) => { | ||
log = _log; | ||
setLogLevel = _setLogLevel; | ||
getConfig = _getConfig; | ||
sanitizeText = _sanitizeText; | ||
setupGraphViewbox = _setupGraphViewbox; | ||
}; | ||
*/ |
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,27 +1,27 @@ | ||
// @ts-ignore: TODO Fix ts errors | ||
// import mindmapParser from './parser/mindmap'; | ||
// import * as mindmapDb from './mindmapDb'; | ||
import { mindmapDetector } from './mindmapDetector'; | ||
// import mindmapRenderer from './mindmapRenderer'; | ||
// import mindmapStyles from './styles'; | ||
|
||
import mermaid from 'mermaid'; | ||
if (typeof document !== 'undefined') { | ||
if (window.mermaid && typeof window.mermaid.detectors === 'object') { | ||
window.mermaid.detectors.push({ id: 'mindmap', detector: mindmapDetector }); | ||
} else { | ||
console.error('window.mermaid.detectors not found'); // eslint-disable-line no-console | ||
window.mermaid = {}; | ||
window.mermaid.detectors = [{ id: 'mindmap', detector: mindmapDetector }]; | ||
console.error('Detectors now:', window.mermaid.detectors); // eslint-disable-line no-console | ||
} | ||
|
||
console.log('mindmapDb', mermaid.mermaidAPI.getConfig()); // eslint-disable-line no-console | ||
// registerDiagram() | ||
|
||
// if (typeof document !== 'undefined') { | ||
// /*! | ||
// * Wait for document loaded before starting the execution | ||
// */ | ||
// window.addEventListener( | ||
// 'load', | ||
// () => { | ||
// if (window.mermaid && typeof window.mermaid.detectors === 'object') { | ||
// window.mermaid.detectors.push(mindmapDetector); | ||
// console.log(window.mermaid.detectors); // eslint-disable-line no-console | ||
// } | ||
// }, | ||
// 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 }); | ||
// console.error(window.mermaid.detectors); // eslint-disable-line no-console | ||
} | ||
}, | ||
false | ||
); | ||
} |
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
Oops, something went wrong.