@eventcatalog/core 4.10.5 → 4.10.6
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.
- package/dist/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/{chunk-NWWGCVSE.js → chunk-EB43LSVE.js} +1 -1
- package/dist/{chunk-7PXZNQPR.js → chunk-GMVJ4B2S.js} +1 -1
- package/dist/{chunk-GLEQKW6W.js → chunk-NECJFWMI.js} +1 -1
- package/dist/{chunk-JE6ZSCPU.js → chunk-XFS3XVP2.js} +1 -1
- package/dist/{chunk-RX2XDKHZ.js → chunk-YSWJHMAX.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +1 -1
- package/dist/eventcatalog.js +5 -5
- package/dist/generate.cjs +1 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/src/components/MDX/MermaidFileLoader/MermaidFileLoader.astro +10 -3
- package/eventcatalog/src/pages/diagrams/[id]/[version]/embed.astro +665 -325
- package/eventcatalog/src/remark-plugins/mermaid.ts +48 -1
- package/eventcatalog/src/utils/mermaid-zoom.ts +781 -404
- package/package.json +3 -4
|
@@ -11,15 +11,62 @@ const escapeMap: Record<string, string> = {
|
|
|
11
11
|
|
|
12
12
|
const escapeHtml = (str: string) => str.replace(/[&<>"']/g, (c) => escapeMap[c]);
|
|
13
13
|
|
|
14
|
+
const PLACEMENTS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;
|
|
15
|
+
|
|
16
|
+
export interface MermaidCodeBlockOptions {
|
|
17
|
+
/** Position of the interactive controls */
|
|
18
|
+
placement?: (typeof PLACEMENTS)[number];
|
|
19
|
+
/** Force the interactive controls on or off */
|
|
20
|
+
actions?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parses options from the code fence meta string, e.g.
|
|
25
|
+
*
|
|
26
|
+
* ```mermaid placement="top-left" actions={false}
|
|
27
|
+
*
|
|
28
|
+
* Supports `placement="..."` / `placement='...'` and `actions={true|false}` / `actions=true|false`.
|
|
29
|
+
*/
|
|
30
|
+
export function parseMermaidMeta(meta: string | null | undefined): MermaidCodeBlockOptions {
|
|
31
|
+
const options: MermaidCodeBlockOptions = {};
|
|
32
|
+
if (!meta) return options;
|
|
33
|
+
|
|
34
|
+
const placementMatch = meta.match(/placement=(?:["']([^"']+)["']|\{["']([^"']+)["']\})/);
|
|
35
|
+
const placement = placementMatch?.[1] ?? placementMatch?.[2];
|
|
36
|
+
if (placement && (PLACEMENTS as readonly string[]).includes(placement)) {
|
|
37
|
+
options.placement = placement as MermaidCodeBlockOptions['placement'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const actionsMatch = meta.match(/actions=\{?(true|false)\}?/);
|
|
41
|
+
if (actionsMatch) {
|
|
42
|
+
options.actions = actionsMatch[1] === 'true';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return options;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Builds the `data-*` attributes used by the client-side renderer to configure the controls
|
|
50
|
+
*/
|
|
51
|
+
export function buildControlAttributes(options: MermaidCodeBlockOptions): string {
|
|
52
|
+
const attributes: string[] = [];
|
|
53
|
+
if (options.placement) attributes.push(`data-placement="${options.placement}"`);
|
|
54
|
+
if (options.actions !== undefined) attributes.push(`data-actions="${options.actions}"`);
|
|
55
|
+
return attributes.length > 0 ? ` ${attributes.join(' ')}` : '';
|
|
56
|
+
}
|
|
57
|
+
|
|
14
58
|
export const mermaid: RemarkPlugin<[]> = () => (tree) => {
|
|
15
59
|
visit(tree, 'code', (node) => {
|
|
16
60
|
if (node.lang !== 'mermaid') return;
|
|
17
61
|
|
|
62
|
+
// @ts-ignore meta is present on code nodes
|
|
63
|
+
const controlAttributes = buildControlAttributes(parseMermaidMeta(node.meta));
|
|
64
|
+
|
|
18
65
|
// @ts-ignore test
|
|
19
66
|
node.type = 'html';
|
|
20
67
|
node.value = `
|
|
21
68
|
<div class="mermaid-block pb-4">
|
|
22
|
-
<div class="mermaid border border-[rgb(var(--ec-page-border))] rounded-lg p-1" data-content="${escapeHtml(node.value)}">
|
|
69
|
+
<div class="mermaid border border-[rgb(var(--ec-page-border))] rounded-lg p-1" data-content="${escapeHtml(node.value)}"${controlAttributes}>
|
|
23
70
|
<p class="text-[rgb(var(--ec-page-text-muted))]">Loading graph...</p>
|
|
24
71
|
</div>
|
|
25
72
|
</div>
|