From da6bb9498a479e4aed598e76b5c06f197912d063 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sun, 6 Nov 2022 22:46:57 +0000 Subject: [PATCH] fix(mermaid): fix mermaid.render types The cb param of mermaid.render should be optional, and mermaid.render returns an SVG string instead of `void`. --- packages/mermaid/src/mermaid.ts | 4 ++-- packages/mermaid/src/mermaidAPI.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index 2a11088e6..7d7385c95 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -482,9 +482,9 @@ const parseAsync = (txt: string) => { const renderAsync = ( id: string, text: string, - cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void, + cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, container?: Element -): Promise => { +): Promise => { return new Promise((resolve, reject) => { // This promise will resolve when the mermaidAPI.render call is done. // It will be queued first and will be executed when it is first in line diff --git a/packages/mermaid/src/mermaidAPI.ts b/packages/mermaid/src/mermaidAPI.ts index 90ab618e2..faba5fef8 100644 --- a/packages/mermaid/src/mermaidAPI.ts +++ b/packages/mermaid/src/mermaidAPI.ts @@ -115,19 +115,19 @@ export const decodeEntities = function (text: string): string { * * @param {string} id The id of the element to be rendered * @param {string} text The graph definition - * @param {(svgCode: string, bindFunctions?: (element: Element) => void) => void} cb Callback which + * @param cb - Optional callback which * is called after rendering is finished with the svg code as inparam. * @param {Element} container Selector to element in which a div with the graph temporarily will be * inserted. If one is provided a hidden div will be inserted in the body of the page instead. The * element will be removed when rendering is completed. - * @returns {void} + * @returns Returns the rendered element as a string containing the SVG definition. */ const render = function ( id: string, text: string, - cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void, + cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, container?: Element -): void { +): string { addDiagrams(); configApi.reset(); text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;; @@ -401,9 +401,9 @@ const render = function ( const renderAsync = async function ( id: string, text: string, - cb: (svgCode: string, bindFunctions?: (element: Element) => void) => void, + cb?: (svgCode: string, bindFunctions?: (element: Element) => void) => void, container?: Element -): Promise { +): Promise { addDiagrams(); configApi.reset(); text = text.replace(/\r\n?/g, '\n'); // parser problems on CRLF ignore all CR and leave LF;;