@diplodoc/mermaid-extension 2.0.0 → 2.1.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.
@@ -1,6 +1,7 @@
1
- import type { InitConfig, RunOptions } from '../types';
1
+ import type { InitConfig, LayoutLoaders, RunOptions } from '../types';
2
2
  export type RuntimeOptions = {
3
+ layoutLoaders?: LayoutLoaders;
3
4
  onError?: (error: unknown) => void;
4
5
  };
5
6
  export declare function MermaidRuntime(props: InitConfig & RunOptions & RuntimeOptions): null;
6
- export declare function useMermaid(): (config: InitConfig, options?: RunOptions) => Promise<void>;
7
+ export declare function useMermaid(): (config: InitConfig, options?: RunOptions, layoutLoaders?: LayoutLoaders) => Promise<void>;
@@ -21,19 +21,30 @@ function omit(object, props) {
21
21
  }
22
22
  function MermaidRuntime(props) {
23
23
  const renderMermaid = useMermaid();
24
- const config = omit(props, ["querySelector", "nodes", "nonce", "onError"]);
24
+ const config = omit(props, [
25
+ "querySelector",
26
+ "nodes",
27
+ "nonce",
28
+ "onError",
29
+ "layoutLoaders"
30
+ ]);
25
31
  const options = pick(props, ["querySelector", "nodes", "nonce"]);
26
32
  useEffect(() => {
27
- renderMermaid(config, options).catch(props.onError || (() => {
28
- }));
33
+ renderMermaid(config, options, props.layoutLoaders).catch(
34
+ props.onError || (() => {
35
+ })
36
+ );
29
37
  });
30
38
  return null;
31
39
  }
32
40
  function useMermaid() {
33
41
  const [mermaid, setMermaid] = useState(null);
34
42
  const render = useCallback(
35
- async (config, options) => {
43
+ async (config, options, layoutLoaders) => {
36
44
  if (mermaid) {
45
+ if (layoutLoaders) {
46
+ mermaid.registerLayoutLoaders(layoutLoaders);
47
+ }
37
48
  mermaid.initialize(config);
38
49
  return mermaid.run(options);
39
50
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/react/index.ts"],
4
- "sourcesContent": ["import type {InitConfig, RunOptions} from '../types';\n\nimport {useCallback, useEffect, useState} from 'react';\n\nexport type RuntimeOptions = {\n onError?: (error: unknown) => void;\n};\n\nfunction pick<\n O extends Hash,\n P extends string,\n R extends {\n [K in P]: O[K];\n },\n>(object: O, props: readonly P[]): R {\n return Object.keys(object).reduce((acc, key) => {\n if ((props as readonly string[]).includes(key)) {\n acc[key] = object[key];\n }\n\n return acc;\n }, {} as Hash) as R;\n}\n\nfunction omit<\n O extends Hash,\n P extends string,\n R extends {\n [K in keyof Omit<O, P>]: O[K];\n },\n>(object: O, props: readonly P[]): R {\n return Object.keys(object).reduce(\n (acc, key) => {\n if (!(props as readonly string[]).includes(key)) {\n acc[key] = object[key];\n }\n\n return acc;\n },\n {} as Record<string, unknown>,\n ) as R;\n}\n\nexport function MermaidRuntime(props: InitConfig & RunOptions & RuntimeOptions) {\n const renderMermaid = useMermaid();\n const config = omit(props as Hash, ['querySelector', 'nodes', 'nonce', 'onError']);\n const options = pick(props as Hash, ['querySelector', 'nodes', 'nonce']);\n\n useEffect(() => {\n renderMermaid(config, options as Hash).catch(props.onError || (() => {}));\n });\n\n return null;\n}\n\nexport function useMermaid() {\n const [mermaid, setMermaid] = useState<Parameters<Callback>[0] | null>(null);\n const render = useCallback(\n async (config: InitConfig, options?: RunOptions) => {\n if (mermaid) {\n mermaid.initialize(config);\n return mermaid.run(options);\n }\n },\n [mermaid],\n );\n\n useEffect(() => {\n (window.mermaidJsonp = window.mermaidJsonp || []).push(setMermaid);\n\n return () => {\n const index = window.mermaidJsonp.indexOf(setMermaid);\n if (index > -1) {\n window.mermaidJsonp.splice(index, 1);\n }\n };\n }, []);\n\n return render;\n}\n"],
5
- "mappings": ";AAEA,SAAQ,aAAa,WAAW,gBAAe;AAM/C,SAAS,KAMP,QAAW,OAAwB;AACjC,SAAO,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC5C,QAAK,MAA4B,SAAS,GAAG,GAAG;AAC5C,UAAI,GAAG,IAAI,OAAO,GAAG;AAAA,IACzB;AAEA,WAAO;AAAA,EACX,GAAG,CAAC,CAAS;AACjB;AAEA,SAAS,KAMP,QAAW,OAAwB;AACjC,SAAO,OAAO,KAAK,MAAM,EAAE;AAAA,IACvB,CAAC,KAAK,QAAQ;AACV,UAAI,CAAE,MAA4B,SAAS,GAAG,GAAG;AAC7C,YAAI,GAAG,IAAI,OAAO,GAAG;AAAA,MACzB;AAEA,aAAO;AAAA,IACX;AAAA,IACA,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,eAAe,OAAiD;AAC5E,QAAM,gBAAgB,WAAW;AACjC,QAAM,SAAS,KAAK,OAAe,CAAC,iBAAiB,SAAS,SAAS,SAAS,CAAC;AACjF,QAAM,UAAU,KAAK,OAAe,CAAC,iBAAiB,SAAS,OAAO,CAAC;AAEvE,YAAU,MAAM;AACZ,kBAAc,QAAQ,OAAe,EAAE,MAAM,MAAM,YAAY,MAAM;AAAA,IAAC,EAAE;AAAA,EAC5E,CAAC;AAED,SAAO;AACX;AAEO,SAAS,aAAa;AACzB,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyC,IAAI;AAC3E,QAAM,SAAS;AAAA,IACX,OAAO,QAAoB,YAAyB;AAChD,UAAI,SAAS;AACT,gBAAQ,WAAW,MAAM;AACzB,eAAO,QAAQ,IAAI,OAAO;AAAA,MAC9B;AAAA,IACJ;AAAA,IACA,CAAC,OAAO;AAAA,EACZ;AAEA,YAAU,MAAM;AACZ,KAAC,OAAO,eAAe,OAAO,gBAAgB,CAAC,GAAG,KAAK,UAAU;AAEjE,WAAO,MAAM;AACT,YAAM,QAAQ,OAAO,aAAa,QAAQ,UAAU;AACpD,UAAI,QAAQ,IAAI;AACZ,eAAO,aAAa,OAAO,OAAO,CAAC;AAAA,MACvC;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,CAAC;AAEL,SAAO;AACX;",
4
+ "sourcesContent": ["import type {InitConfig, LayoutLoaders, RunOptions} from '../types';\n\nimport {useCallback, useEffect, useState} from 'react';\n\nexport type RuntimeOptions = {\n layoutLoaders?: LayoutLoaders;\n onError?: (error: unknown) => void;\n};\n\nfunction pick<\n O extends Hash,\n P extends string,\n R extends {\n [K in P]: O[K];\n },\n>(object: O, props: readonly P[]): R {\n return Object.keys(object).reduce((acc, key) => {\n if ((props as readonly string[]).includes(key)) {\n acc[key] = object[key];\n }\n\n return acc;\n }, {} as Hash) as R;\n}\n\nfunction omit<\n O extends Hash,\n P extends string,\n R extends {\n [K in keyof Omit<O, P>]: O[K];\n },\n>(object: O, props: readonly P[]): R {\n return Object.keys(object).reduce(\n (acc, key) => {\n if (!(props as readonly string[]).includes(key)) {\n acc[key] = object[key];\n }\n\n return acc;\n },\n {} as Record<string, unknown>,\n ) as R;\n}\n\nexport function MermaidRuntime(props: InitConfig & RunOptions & RuntimeOptions) {\n const renderMermaid = useMermaid();\n const config = omit(props as Hash, [\n 'querySelector',\n 'nodes',\n 'nonce',\n 'onError',\n 'layoutLoaders',\n ]);\n const options = pick(props as Hash, ['querySelector', 'nodes', 'nonce']);\n\n useEffect(() => {\n renderMermaid(config, options as Hash, props.layoutLoaders).catch(\n props.onError || (() => {}),\n );\n });\n\n return null;\n}\n\nexport function useMermaid() {\n const [mermaid, setMermaid] = useState<Parameters<Callback>[0] | null>(null);\n const render = useCallback(\n async (config: InitConfig, options?: RunOptions, layoutLoaders?: LayoutLoaders) => {\n if (mermaid) {\n if (layoutLoaders) {\n mermaid.registerLayoutLoaders(layoutLoaders);\n }\n mermaid.initialize(config);\n return mermaid.run(options);\n }\n },\n [mermaid],\n );\n\n useEffect(() => {\n (window.mermaidJsonp = window.mermaidJsonp || []).push(setMermaid);\n\n return () => {\n const index = window.mermaidJsonp.indexOf(setMermaid);\n if (index > -1) {\n window.mermaidJsonp.splice(index, 1);\n }\n };\n }, []);\n\n return render;\n}\n"],
5
+ "mappings": ";AAEA,SAAQ,aAAa,WAAW,gBAAe;AAO/C,SAAS,KAMP,QAAW,OAAwB;AACjC,SAAO,OAAO,KAAK,MAAM,EAAE,OAAO,C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