@redocly/theme 0.64.0-next.3 → 0.64.0-next.4
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/lib/components/Catalog/CatalogTags.js +5 -2
- package/lib/components/LanguagePicker/LanguagePicker.js +5 -6
- package/lib/components/Search/SearchAiMessage.js +9 -6
- package/lib/components/SvgViewer/SvgViewer.js +0 -3
- package/lib/components/SvgViewer/variables.js +1 -1
- package/lib/core/constants/search.d.ts +3 -3
- package/lib/core/contexts/MarkdownLinkContext.d.ts +5 -0
- package/lib/core/contexts/MarkdownLinkContext.js +6 -0
- package/lib/core/contexts/index.d.ts +1 -0
- package/lib/core/contexts/index.js +1 -0
- package/lib/core/styles/dark.js +28 -32
- package/lib/core/styles/global.js +2 -2
- package/lib/core/types/hooks.d.ts +2 -9
- package/lib/core/types/l10n.d.ts +1 -1
- package/lib/core/types/search.d.ts +1 -1
- package/lib/markdoc/attributes/diagram-file.d.ts +5 -0
- package/lib/markdoc/attributes/diagram-file.js +16 -0
- package/lib/markdoc/components/Diagram/Diagram.d.ts +15 -0
- package/lib/markdoc/components/Diagram/Diagram.js +135 -0
- package/lib/markdoc/components/Diagram/variables.d.ts +1 -0
- package/lib/markdoc/components/Diagram/variables.js +15 -0
- package/lib/markdoc/components/MarkdownLink/MarkdownLink.d.ts +7 -0
- package/lib/markdoc/components/MarkdownLink/MarkdownLink.js +61 -0
- package/lib/markdoc/components/default.d.ts +2 -1
- package/lib/markdoc/components/default.js +2 -1
- package/lib/markdoc/default.d.ts +7 -0
- package/lib/markdoc/default.js +3 -0
- package/lib/markdoc/tags/diagram.d.ts +2 -0
- package/lib/markdoc/tags/diagram.js +63 -0
- package/package.json +3 -3
- package/src/components/Catalog/CatalogTags.tsx +6 -1
- package/src/components/LanguagePicker/LanguagePicker.tsx +5 -5
- package/src/components/Search/SearchAiMessage.tsx +15 -10
- package/src/components/SvgViewer/SvgViewer.tsx +0 -4
- package/src/components/SvgViewer/variables.ts +1 -1
- package/src/core/constants/search.ts +2 -3
- package/src/core/contexts/MarkdownLinkContext.tsx +9 -0
- package/src/core/contexts/index.ts +1 -0
- package/src/core/styles/dark.ts +0 -4
- package/src/core/styles/global.ts +2 -2
- package/src/core/types/hooks.ts +2 -7
- package/src/core/types/l10n.ts +9 -9
- package/src/core/types/search.ts +1 -1
- package/src/markdoc/attributes/diagram-file.ts +9 -0
- package/src/markdoc/components/Diagram/Diagram.tsx +173 -0
- package/src/markdoc/components/Diagram/variables.ts +12 -0
- package/src/markdoc/components/MarkdownLink/MarkdownLink.tsx +21 -0
- package/src/markdoc/components/default.ts +2 -1
- package/src/markdoc/default.ts +3 -0
- package/src/markdoc/tags/diagram.ts +73 -0
- package/lib/components/SvgViewer/variables.dark.d.ts +0 -1
- package/lib/components/SvgViewer/variables.dark.js +0 -8
- package/lib/markdoc/components/Mermaid/Mermaid.d.ts +0 -9
- package/lib/markdoc/components/Mermaid/Mermaid.js +0 -94
- package/lib/markdoc/components/Mermaid/variables.d.ts +0 -1
- package/lib/markdoc/components/Mermaid/variables.dark.d.ts +0 -1
- package/lib/markdoc/components/Mermaid/variables.dark.js +0 -8
- package/lib/markdoc/components/Mermaid/variables.js +0 -16
- package/src/components/SvgViewer/variables.dark.ts +0 -5
- package/src/markdoc/components/Mermaid/Mermaid.tsx +0 -93
- package/src/markdoc/components/Mermaid/variables.dark.ts +0 -5
- package/src/markdoc/components/Mermaid/variables.ts +0 -13
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import type { JSX } from 'react';
|
|
5
|
+
|
|
6
|
+
import { concatClassNames } from '@redocly/theme/core/utils';
|
|
7
|
+
import { useColorSwitcher } from '@redocly/theme/core/hooks';
|
|
8
|
+
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
9
|
+
import { SvgViewer } from '@redocly/theme/components/SvgViewer/SvgViewer';
|
|
10
|
+
|
|
11
|
+
type DiagramProps = {
|
|
12
|
+
id?: string;
|
|
13
|
+
diagramHtml: string;
|
|
14
|
+
diagramHtmlDark?: string;
|
|
15
|
+
diagramError?: string;
|
|
16
|
+
diagramType: string;
|
|
17
|
+
align?: 'left' | 'center' | 'right';
|
|
18
|
+
width?: string;
|
|
19
|
+
'data-source'?: string;
|
|
20
|
+
'data-hash'?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function Diagram({
|
|
25
|
+
id,
|
|
26
|
+
diagramHtml,
|
|
27
|
+
diagramHtmlDark,
|
|
28
|
+
diagramError,
|
|
29
|
+
diagramType,
|
|
30
|
+
align,
|
|
31
|
+
width,
|
|
32
|
+
'data-source': dataSource,
|
|
33
|
+
'data-hash': dataHash,
|
|
34
|
+
className,
|
|
35
|
+
}: DiagramProps): JSX.Element {
|
|
36
|
+
const { useTranslate } = useThemeHooks();
|
|
37
|
+
const { translate } = useTranslate();
|
|
38
|
+
const { activeColorMode } = useColorSwitcher();
|
|
39
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
40
|
+
const activeDiagramHtml =
|
|
41
|
+
activeColorMode === 'dark' ? diagramHtmlDark || diagramHtml : diagramHtml;
|
|
42
|
+
|
|
43
|
+
const open = () => setIsOpen(true);
|
|
44
|
+
const close = () => setIsOpen(false);
|
|
45
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
46
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
open();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (diagramError) {
|
|
53
|
+
return (
|
|
54
|
+
<ErrorWrapper id={id} className={concatClassNames('diagram-error', className)}>
|
|
55
|
+
{diagramError}
|
|
56
|
+
</ErrorWrapper>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<Wrapper
|
|
63
|
+
id={id}
|
|
64
|
+
$width={width}
|
|
65
|
+
className={concatClassNames(`diagram-wrapper diagram-${diagramType}`, className)}
|
|
66
|
+
data-component-name="Markdoc/Diagram/Diagram"
|
|
67
|
+
data-diagram-type={diagramType}
|
|
68
|
+
data-source={dataSource}
|
|
69
|
+
data-hash={dataHash}
|
|
70
|
+
onClick={open}
|
|
71
|
+
onKeyDown={handleKeyDown}
|
|
72
|
+
role="button"
|
|
73
|
+
tabIndex={0}
|
|
74
|
+
aria-label={translate('diagram.openFullscreen', 'Click to open diagram in fullscreen')}
|
|
75
|
+
>
|
|
76
|
+
<DiagramVariant
|
|
77
|
+
$align={align}
|
|
78
|
+
$colorMode="light"
|
|
79
|
+
className={`diagram-variant diagram-variant-light diagram-${diagramType}`}
|
|
80
|
+
dangerouslySetInnerHTML={{ __html: diagramHtml }}
|
|
81
|
+
/>
|
|
82
|
+
{diagramHtmlDark ? (
|
|
83
|
+
<DiagramVariant
|
|
84
|
+
$align={align}
|
|
85
|
+
$colorMode="dark"
|
|
86
|
+
className={`diagram-variant diagram-variant-dark diagram-${diagramType}`}
|
|
87
|
+
dangerouslySetInnerHTML={{ __html: diagramHtmlDark }}
|
|
88
|
+
/>
|
|
89
|
+
) : null}
|
|
90
|
+
</Wrapper>
|
|
91
|
+
<SvgViewer
|
|
92
|
+
isOpen={isOpen}
|
|
93
|
+
onClose={close}
|
|
94
|
+
labels={{
|
|
95
|
+
zoomIn: translate('diagram.zoomIn', 'Zoom in'),
|
|
96
|
+
zoomOut: translate('diagram.zoomOut', 'Zoom out'),
|
|
97
|
+
fitToView: translate('diagram.reset', 'Fit to view'),
|
|
98
|
+
close: translate('diagram.close', 'Close'),
|
|
99
|
+
dialogLabel: translate('diagram.viewer', 'Diagram viewer'),
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<ViewerContent
|
|
103
|
+
className={`diagram-viewer-content diagram-${diagramType}`}
|
|
104
|
+
dangerouslySetInnerHTML={{ __html: activeDiagramHtml }}
|
|
105
|
+
/>
|
|
106
|
+
</SvgViewer>
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const Wrapper = styled.div<{ $width?: string }>`
|
|
112
|
+
background-color: var(--diagram-bg-color);
|
|
113
|
+
border-radius: var(--diagram-border-radius);
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
transition: box-shadow 0.2s ease;
|
|
116
|
+
|
|
117
|
+
&:hover,
|
|
118
|
+
&:focus {
|
|
119
|
+
outline: none;
|
|
120
|
+
box-shadow: 0 0 0 2px var(--border-color-input-focus);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
svg {
|
|
124
|
+
max-width: 100%;
|
|
125
|
+
display: block;
|
|
126
|
+
${({ $width }) => ($width ? `width: ${$width} !important; height: auto !important;` : '')}
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
const DiagramVariant = styled.div<{ $colorMode: 'light' | 'dark'; $align?: DiagramProps['align'] }>`
|
|
131
|
+
display: flex;
|
|
132
|
+
justify-content: ${({ $align }) => {
|
|
133
|
+
switch ($align) {
|
|
134
|
+
case 'center':
|
|
135
|
+
return 'center';
|
|
136
|
+
case 'right':
|
|
137
|
+
return 'flex-end';
|
|
138
|
+
default:
|
|
139
|
+
return 'flex-start';
|
|
140
|
+
}
|
|
141
|
+
}};
|
|
142
|
+
width: 100%;
|
|
143
|
+
${({ $colorMode }) =>
|
|
144
|
+
$colorMode === 'dark'
|
|
145
|
+
? `
|
|
146
|
+
html:not(.dark) && {
|
|
147
|
+
display: none;
|
|
148
|
+
}
|
|
149
|
+
`
|
|
150
|
+
: `
|
|
151
|
+
html.dark && {
|
|
152
|
+
display: none;
|
|
153
|
+
}
|
|
154
|
+
`}
|
|
155
|
+
`;
|
|
156
|
+
|
|
157
|
+
const ErrorWrapper = styled.div`
|
|
158
|
+
border: 1px solid var(--color-error-border);
|
|
159
|
+
border-radius: var(--diagram-border-radius);
|
|
160
|
+
background: var(--color-error-bg);
|
|
161
|
+
color: var(--color-error-text);
|
|
162
|
+
font-size: var(--font-size-sm);
|
|
163
|
+
padding: var(--spacing-sm);
|
|
164
|
+
white-space: pre-wrap;
|
|
165
|
+
word-break: break-word;
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
const ViewerContent = styled.div`
|
|
169
|
+
svg {
|
|
170
|
+
display: block;
|
|
171
|
+
max-width: none !important;
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { css } from "styled-components";
|
|
2
|
+
|
|
3
|
+
export const diagram = css`
|
|
4
|
+
/**
|
|
5
|
+
* @tokens Diagram
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
--diagram-bg-color: var(--bg-color-raised); // @presenter Color
|
|
9
|
+
--diagram-border-radius: var(--border-radius-lg); // @presenter BorderRadius
|
|
10
|
+
|
|
11
|
+
// @tokens End
|
|
12
|
+
`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { useCallback, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { ComponentProps, ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
import { MarkdownLinkContext } from '@redocly/theme/core/contexts';
|
|
6
|
+
import { Link } from '@redocly/theme/components/Link/Link';
|
|
7
|
+
|
|
8
|
+
type MarkdownLinkProps = Omit<ComponentProps<typeof Link>, 'to' | 'onClick'> & {
|
|
9
|
+
href: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function MarkdownLink({ href, ...props }: MarkdownLinkProps): ReactElement {
|
|
13
|
+
const markdownLinkContext = useContext(MarkdownLinkContext);
|
|
14
|
+
const onClick = useCallback(() => {
|
|
15
|
+
markdownLinkContext?.onMarkdownLinkClick?.();
|
|
16
|
+
}, [markdownLinkContext]);
|
|
17
|
+
|
|
18
|
+
const linkProps = { ...props, languageInsensitive: true, onClick };
|
|
19
|
+
|
|
20
|
+
return <Link to={href} {...linkProps} />;
|
|
21
|
+
}
|
|
@@ -2,7 +2,7 @@ export * from '@redocly/theme/markdoc/components/Admonition/Admonition';
|
|
|
2
2
|
export * from '@redocly/theme/markdoc/components/InlineSvg/InlineSvg';
|
|
3
3
|
export * from '@redocly/theme/markdoc/components/MarkdocExample/MarkdocExample';
|
|
4
4
|
export * from '@redocly/theme/markdoc/components/Heading/Heading';
|
|
5
|
-
export * from '@redocly/theme/markdoc/components/
|
|
5
|
+
export * from '@redocly/theme/markdoc/components/Diagram/Diagram';
|
|
6
6
|
export * from '@redocly/theme/markdoc/components/HtmlBlock/HtmlBlock';
|
|
7
7
|
export * from '@redocly/theme/markdoc/components/Tabs/Tab';
|
|
8
8
|
export * from '@redocly/theme/markdoc/components/Tabs/TabList';
|
|
@@ -22,3 +22,4 @@ export * from '@redocly/theme/markdoc/components/CodeGroup/CodeGroup';
|
|
|
22
22
|
export * from '@redocly/theme/markdoc/components/Icon/Icon';
|
|
23
23
|
export * from '@redocly/theme/markdoc/components/ConnectMCP/ConnectMCP';
|
|
24
24
|
export * from '@redocly/theme/markdoc/components/LoginButton/LoginButton';
|
|
25
|
+
export * from '@redocly/theme/markdoc/components/MarkdownLink/MarkdownLink';
|
package/src/markdoc/default.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* Attributes */
|
|
2
2
|
export * from '@redocly/theme/markdoc/attributes/code-snippet-file';
|
|
3
|
+
export * from '@redocly/theme/markdoc/attributes/diagram-file';
|
|
3
4
|
export * from '@redocly/theme/markdoc/attributes/img-src';
|
|
4
5
|
export * from '@redocly/theme/markdoc/attributes/img-srcset';
|
|
5
6
|
export * from '@redocly/theme/markdoc/attributes/relative-path';
|
|
@@ -27,6 +28,7 @@ import { codeGroup } from '@redocly/theme/markdoc/tags/code-group';
|
|
|
27
28
|
import { icon } from '@redocly/theme/markdoc/tags/icon';
|
|
28
29
|
import { connectMcp } from '@redocly/theme/markdoc/tags/connect-mcp';
|
|
29
30
|
import { loginButton } from '@redocly/theme/markdoc/tags/login-button';
|
|
31
|
+
import { diagram } from '@redocly/theme/markdoc/tags/diagram';
|
|
30
32
|
|
|
31
33
|
export const tags = {
|
|
32
34
|
[admonition.tagName]: admonition.schema,
|
|
@@ -49,4 +51,5 @@ export const tags = {
|
|
|
49
51
|
[icon.tagName]: icon.schema,
|
|
50
52
|
[connectMcp.tagName]: connectMcp.schema,
|
|
51
53
|
[loginButton.tagName]: loginButton.schema,
|
|
54
|
+
[diagram.tagName]: diagram.schema,
|
|
52
55
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import markdoc from '@markdoc/markdoc';
|
|
2
|
+
|
|
3
|
+
import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
|
|
4
|
+
|
|
5
|
+
import { DiagramFile } from '@redocly/theme/markdoc/attributes/diagram-file';
|
|
6
|
+
|
|
7
|
+
const DIAGRAM_TYPES = ['mermaid', 'plantuml', 'excalidraw'];
|
|
8
|
+
const DIAGRAM_ALIGNMENTS = ['left', 'center', 'right'];
|
|
9
|
+
|
|
10
|
+
export const diagram: MarkdocSchemaWrapper = {
|
|
11
|
+
schema: {
|
|
12
|
+
attributes: {
|
|
13
|
+
file: { type: DiagramFile, required: true },
|
|
14
|
+
type: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true,
|
|
17
|
+
matches: DIAGRAM_TYPES,
|
|
18
|
+
},
|
|
19
|
+
align: {
|
|
20
|
+
type: String,
|
|
21
|
+
matches: DIAGRAM_ALIGNMENTS,
|
|
22
|
+
},
|
|
23
|
+
width: {
|
|
24
|
+
type: String,
|
|
25
|
+
},
|
|
26
|
+
rawContent: { type: String, render: false }, // internal — populated by resolver
|
|
27
|
+
},
|
|
28
|
+
render: 'Diagram',
|
|
29
|
+
selfClosing: true,
|
|
30
|
+
transform: (node, config) => {
|
|
31
|
+
const attributes = node.transformAttributes(config);
|
|
32
|
+
const rawContent = node.attributes.rawContent;
|
|
33
|
+
const diagramType = node.attributes.type;
|
|
34
|
+
|
|
35
|
+
if (typeof rawContent === 'string') {
|
|
36
|
+
return new markdoc.Tag(
|
|
37
|
+
'Diagram',
|
|
38
|
+
{
|
|
39
|
+
...attributes,
|
|
40
|
+
diagramType,
|
|
41
|
+
diagramSource: rawContent,
|
|
42
|
+
},
|
|
43
|
+
[],
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new markdoc.Tag(node.tag, attributes, []);
|
|
48
|
+
},
|
|
49
|
+
validate(node) {
|
|
50
|
+
const errors = [];
|
|
51
|
+
const type = node.attributes.type;
|
|
52
|
+
if (type && !DIAGRAM_TYPES.includes(type)) {
|
|
53
|
+
errors.push({
|
|
54
|
+
id: 'invalid-diagram-type',
|
|
55
|
+
level: 'error' as const,
|
|
56
|
+
message: `Invalid diagram type "${type}". Must be one of: ${DIAGRAM_TYPES.join(', ')}`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const align = node.attributes.align;
|
|
60
|
+
if (align && !DIAGRAM_ALIGNMENTS.includes(align)) {
|
|
61
|
+
errors.push({
|
|
62
|
+
id: 'invalid-diagram-align',
|
|
63
|
+
level: 'error' as const,
|
|
64
|
+
message: `Invalid diagram align "${align}". Must be one of: ${DIAGRAM_ALIGNMENTS.join(
|
|
65
|
+
', ',
|
|
66
|
+
)}`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return errors;
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
tagName: 'diagram',
|
|
73
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const svgViewerDarkMode: import("styled-components").FlattenSimpleInterpolation;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.svgViewerDarkMode = void 0;
|
|
4
|
-
const styled_components_1 = require("styled-components");
|
|
5
|
-
exports.svgViewerDarkMode = (0, styled_components_1.css) `
|
|
6
|
-
--svg-viewer-bg-color: var(--color-warm-grey-9);
|
|
7
|
-
`;
|
|
8
|
-
//# sourceMappingURL=variables.dark.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { JSX } from 'react';
|
|
2
|
-
type MermaidProps = {
|
|
3
|
-
diagramHtml: string;
|
|
4
|
-
'data-source'?: string;
|
|
5
|
-
'data-hash'?: string;
|
|
6
|
-
className?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function Mermaid({ diagramHtml, 'data-source': dataSource, 'data-hash': dataHash, className, }: MermaidProps): JSX.Element;
|
|
9
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Mermaid = Mermaid;
|
|
40
|
-
const react_1 = __importStar(require("react"));
|
|
41
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
42
|
-
const utils_1 = require("../../../core/utils");
|
|
43
|
-
const hooks_1 = require("../../../core/hooks");
|
|
44
|
-
const SvgViewer_1 = require("../../../components/SvgViewer/SvgViewer");
|
|
45
|
-
function Mermaid({ diagramHtml, 'data-source': dataSource, 'data-hash': dataHash, className, }) {
|
|
46
|
-
const { useTranslate } = (0, hooks_1.useThemeHooks)();
|
|
47
|
-
const { translate } = useTranslate();
|
|
48
|
-
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
49
|
-
const open = () => setIsOpen(true);
|
|
50
|
-
const close = () => setIsOpen(false);
|
|
51
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
52
|
-
react_1.default.createElement(Wrapper, { className: (0, utils_1.concatClassNames)('mermaid-wrapper', className), dangerouslySetInnerHTML: { __html: diagramHtml }, "data-component-name": "Markdoc/Mermaid/Mermaid", "data-source": dataSource, "data-hash": dataHash, onClick: open, onKeyDown: (e) => e.key === 'Enter' || (e.key === ' ' && open()), role: "button", tabIndex: 0, "aria-label": translate('mermaid.openFullscreen', 'Click to open diagram in fullscreen') }),
|
|
53
|
-
react_1.default.createElement(SvgViewer_1.SvgViewer, { isOpen: isOpen, onClose: close, labels: {
|
|
54
|
-
zoomIn: translate('mermaid.zoomIn', 'Zoom in'),
|
|
55
|
-
zoomOut: translate('mermaid.zoomOut', 'Zoom out'),
|
|
56
|
-
fitToView: translate('mermaid.reset', 'Fit to view'),
|
|
57
|
-
close: translate('mermaid.close', 'Close'),
|
|
58
|
-
dialogLabel: translate('mermaid.viewer', 'Mermaid diagram viewer'),
|
|
59
|
-
} },
|
|
60
|
-
react_1.default.createElement(ViewerContent, { dangerouslySetInnerHTML: { __html: diagramHtml } }))));
|
|
61
|
-
}
|
|
62
|
-
const Wrapper = styled_components_1.default.div `
|
|
63
|
-
background-color: var(--mermaid-bg-color);
|
|
64
|
-
border-radius: var(--mermaid-border-radius);
|
|
65
|
-
cursor: pointer;
|
|
66
|
-
transition: box-shadow 0.2s ease;
|
|
67
|
-
|
|
68
|
-
&:hover,
|
|
69
|
-
&:focus {
|
|
70
|
-
outline: none;
|
|
71
|
-
box-shadow: 0 0 0 2px var(--border-color-input-focus);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
* {
|
|
75
|
-
font-family: var(--mermaid-font-family) !important;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.mermaid > svg {
|
|
79
|
-
font-size: var(--font-size-base) !important;
|
|
80
|
-
max-width: 100%;
|
|
81
|
-
}
|
|
82
|
-
`;
|
|
83
|
-
const ViewerContent = styled_components_1.default.div `
|
|
84
|
-
* {
|
|
85
|
-
font-family: var(--mermaid-font-family) !important;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.mermaid > svg {
|
|
89
|
-
font-size: var(--font-size-base) !important;
|
|
90
|
-
display: block;
|
|
91
|
-
max-width: none !important;
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
//# sourceMappingURL=Mermaid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const mermaid: import("styled-components").FlattenSimpleInterpolation;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const mermaidDarkMode: import("styled-components").FlattenSimpleInterpolation;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mermaidDarkMode = void 0;
|
|
4
|
-
const styled_components_1 = require("styled-components");
|
|
5
|
-
exports.mermaidDarkMode = (0, styled_components_1.css) `
|
|
6
|
-
--mermaid-bg-color: var(--color-warm-grey-8); // @presenter Color
|
|
7
|
-
`;
|
|
8
|
-
//# sourceMappingURL=variables.dark.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mermaid = void 0;
|
|
4
|
-
const styled_components_1 = require("styled-components");
|
|
5
|
-
exports.mermaid = (0, styled_components_1.css) `
|
|
6
|
-
/**
|
|
7
|
-
* @tokens Mermaid
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
--mermaid-bg-color: var(--bg-color-raised); // @presenter Color
|
|
11
|
-
--mermaid-border-radius: var(--border-radius-lg); // @presenter BorderRadius
|
|
12
|
-
--mermaid-font-family: var(--font-family-base); // @presenter FontFamily
|
|
13
|
-
|
|
14
|
-
// @tokens End
|
|
15
|
-
`;
|
|
16
|
-
//# sourceMappingURL=variables.js.map
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
-
import type { JSX } from 'react';
|
|
5
|
-
|
|
6
|
-
import { concatClassNames } from '@redocly/theme/core/utils';
|
|
7
|
-
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
8
|
-
import { SvgViewer } from '@redocly/theme/components/SvgViewer/SvgViewer';
|
|
9
|
-
|
|
10
|
-
type MermaidProps = {
|
|
11
|
-
diagramHtml: string;
|
|
12
|
-
'data-source'?: string;
|
|
13
|
-
'data-hash'?: string;
|
|
14
|
-
className?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function Mermaid({
|
|
18
|
-
diagramHtml,
|
|
19
|
-
'data-source': dataSource,
|
|
20
|
-
'data-hash': dataHash,
|
|
21
|
-
className,
|
|
22
|
-
}: MermaidProps): JSX.Element {
|
|
23
|
-
const { useTranslate } = useThemeHooks();
|
|
24
|
-
const { translate } = useTranslate();
|
|
25
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
26
|
-
|
|
27
|
-
const open = () => setIsOpen(true);
|
|
28
|
-
const close = () => setIsOpen(false);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<>
|
|
32
|
-
<Wrapper
|
|
33
|
-
className={concatClassNames('mermaid-wrapper', className)}
|
|
34
|
-
dangerouslySetInnerHTML={{ __html: diagramHtml }}
|
|
35
|
-
data-component-name="Markdoc/Mermaid/Mermaid"
|
|
36
|
-
data-source={dataSource}
|
|
37
|
-
data-hash={dataHash}
|
|
38
|
-
onClick={open}
|
|
39
|
-
onKeyDown={(e) => e.key === 'Enter' || (e.key === ' ' && open())}
|
|
40
|
-
role="button"
|
|
41
|
-
tabIndex={0}
|
|
42
|
-
aria-label={translate('mermaid.openFullscreen', 'Click to open diagram in fullscreen')}
|
|
43
|
-
/>
|
|
44
|
-
<SvgViewer
|
|
45
|
-
isOpen={isOpen}
|
|
46
|
-
onClose={close}
|
|
47
|
-
labels={{
|
|
48
|
-
zoomIn: translate('mermaid.zoomIn', 'Zoom in'),
|
|
49
|
-
zoomOut: translate('mermaid.zoomOut', 'Zoom out'),
|
|
50
|
-
fitToView: translate('mermaid.reset', 'Fit to view'),
|
|
51
|
-
close: translate('mermaid.close', 'Close'),
|
|
52
|
-
dialogLabel: translate('mermaid.viewer', 'Mermaid diagram viewer'),
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<ViewerContent dangerouslySetInnerHTML={{ __html: diagramHtml }} />
|
|
56
|
-
</SvgViewer>
|
|
57
|
-
</>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const Wrapper = styled.div`
|
|
62
|
-
background-color: var(--mermaid-bg-color);
|
|
63
|
-
border-radius: var(--mermaid-border-radius);
|
|
64
|
-
cursor: pointer;
|
|
65
|
-
transition: box-shadow 0.2s ease;
|
|
66
|
-
|
|
67
|
-
&:hover,
|
|
68
|
-
&:focus {
|
|
69
|
-
outline: none;
|
|
70
|
-
box-shadow: 0 0 0 2px var(--border-color-input-focus);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
* {
|
|
74
|
-
font-family: var(--mermaid-font-family) !important;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.mermaid > svg {
|
|
78
|
-
font-size: var(--font-size-base) !important;
|
|
79
|
-
max-width: 100%;
|
|
80
|
-
}
|
|
81
|
-
`;
|
|
82
|
-
|
|
83
|
-
const ViewerContent = styled.div`
|
|
84
|
-
* {
|
|
85
|
-
font-family: var(--mermaid-font-family) !important;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.mermaid > svg {
|
|
89
|
-
font-size: var(--font-size-base) !important;
|
|
90
|
-
display: block;
|
|
91
|
-
max-width: none !important;
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { css } from "styled-components";
|
|
2
|
-
|
|
3
|
-
export const mermaid = css`
|
|
4
|
-
/**
|
|
5
|
-
* @tokens Mermaid
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
--mermaid-bg-color: var(--bg-color-raised); // @presenter Color
|
|
9
|
-
--mermaid-border-radius: var(--border-radius-lg); // @presenter BorderRadius
|
|
10
|
-
--mermaid-font-family: var(--font-family-base); // @presenter FontFamily
|
|
11
|
-
|
|
12
|
-
// @tokens End
|
|
13
|
-
`;
|