@redocly/theme 0.46.5 → 0.47.1
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/Buttons/CopyButton.d.ts +8 -3
- package/lib/components/Buttons/CopyButton.js +4 -3
- package/lib/components/Image/Image.d.ts +5 -0
- package/lib/components/Image/Image.js +3 -2
- package/lib/components/Search/SearchAiResponse.js +1 -1
- package/lib/components/Search/SearchDialog.js +6 -4
- package/lib/components/StatusCode/StatusCode.js +11 -14
- package/lib/core/constants/code-walkthrough.d.ts +1 -0
- package/lib/core/constants/code-walkthrough.js +5 -0
- package/lib/core/constants/index.d.ts +1 -0
- package/lib/core/constants/index.js +1 -0
- package/lib/core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext.d.ts +2 -0
- package/lib/core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext.js +18 -0
- package/lib/core/contexts/CodeWalkthrough/CodeWalkthroughStepsContext.d.ts +2 -0
- package/lib/core/contexts/CodeWalkthrough/CodeWalkthroughStepsContext.js +11 -0
- package/lib/core/contexts/index.d.ts +2 -0
- package/lib/core/contexts/index.js +2 -0
- package/lib/core/hooks/code-walkthrough/__mocks__/MockIntersectionObserver.d.ts +10 -0
- package/lib/core/hooks/code-walkthrough/__mocks__/MockIntersectionObserver.js +55 -0
- package/lib/core/hooks/code-walkthrough/use-code-panel.d.ts +6 -0
- package/lib/core/hooks/code-walkthrough/use-code-panel.js +93 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough-controls.d.ts +22 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough-controls.js +183 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough-steps.d.ts +16 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough-steps.js +117 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough.d.ts +14 -0
- package/lib/core/hooks/code-walkthrough/use-code-walkthrough.js +22 -0
- package/lib/core/hooks/index.d.ts +4 -0
- package/lib/core/hooks/index.js +4 -0
- package/lib/core/styles/global.js +24 -9
- package/lib/core/templates/Markdown.d.ts +8 -2
- package/lib/core/templates/Markdown.js +5 -2
- package/lib/core/types/hooks.d.ts +2 -0
- package/lib/core/types/l10n.d.ts +1 -1
- package/lib/core/utils/download-code-walkthrough.d.ts +4 -0
- package/lib/core/utils/download-code-walkthrough.js +32 -0
- package/lib/core/utils/get-code-walkthrough-file-text.d.ts +4 -0
- package/lib/core/utils/get-code-walkthrough-file-text.js +22 -0
- package/lib/core/utils/get-file-icon.d.ts +2 -0
- package/lib/core/utils/get-file-icon.js +31 -0
- package/lib/core/utils/index.d.ts +5 -0
- package/lib/core/utils/index.js +5 -0
- package/lib/core/utils/js-utils.d.ts +30 -0
- package/lib/core/utils/js-utils.js +41 -0
- package/lib/core/utils/match-code-walkthrough-conditions.d.ts +4 -0
- package/lib/core/utils/match-code-walkthrough-conditions.js +23 -0
- package/lib/core/utils/replace-inputs-with-value.d.ts +3 -0
- package/lib/core/utils/replace-inputs-with-value.js +16 -0
- package/lib/icons/DocumentCssIcon/DocumentCssIcon.d.ts +9 -0
- package/lib/icons/DocumentCssIcon/DocumentCssIcon.js +23 -0
- package/lib/icons/DocumentCssIcon/index.d.ts +1 -0
- package/lib/icons/DocumentCssIcon/index.js +6 -0
- package/lib/icons/DocumentGraphqlIcon/DocumentGraphqlIcon.d.ts +9 -0
- package/lib/icons/DocumentGraphqlIcon/DocumentGraphqlIcon.js +31 -0
- package/lib/icons/DocumentGraphqlIcon/index.d.ts +1 -0
- package/lib/icons/DocumentGraphqlIcon/index.js +6 -0
- package/lib/icons/DocumentHtmlIcon/DocumentHtmlIcon.d.ts +9 -0
- package/lib/icons/DocumentHtmlIcon/DocumentHtmlIcon.js +23 -0
- package/lib/icons/DocumentHtmlIcon/index.d.ts +1 -0
- package/lib/icons/DocumentHtmlIcon/index.js +6 -0
- package/lib/icons/DocumentJsIcon/DocumentJsIcon.d.ts +9 -0
- package/lib/icons/DocumentJsIcon/DocumentJsIcon.js +23 -0
- package/lib/icons/DocumentJsIcon/index.d.ts +1 -0
- package/lib/icons/DocumentJsIcon/index.js +6 -0
- package/lib/icons/DocumentJsonIcon/DocumentJsonIcon.d.ts +9 -0
- package/lib/icons/DocumentJsonIcon/DocumentJsonIcon.js +23 -0
- package/lib/icons/DocumentJsonIcon/index.d.ts +1 -0
- package/lib/icons/DocumentJsonIcon/index.js +6 -0
- package/lib/icons/DocumentMarkdownIcon/DocumentMarkdownIcon.d.ts +9 -0
- package/lib/icons/DocumentMarkdownIcon/DocumentMarkdownIcon.js +23 -0
- package/lib/icons/DocumentMarkdownIcon/index.d.ts +1 -0
- package/lib/icons/DocumentMarkdownIcon/index.js +6 -0
- package/lib/icons/DocumentReactIcon/DocumentReactIcon.d.ts +9 -0
- package/lib/icons/DocumentReactIcon/DocumentReactIcon.js +23 -0
- package/lib/icons/DocumentReactIcon/index.d.ts +1 -0
- package/lib/icons/DocumentReactIcon/index.js +6 -0
- package/lib/icons/DocumentTsIcon/DocumentTsIcon.d.ts +9 -0
- package/lib/icons/DocumentTsIcon/DocumentTsIcon.js +23 -0
- package/lib/icons/DocumentTsIcon/index.d.ts +1 -0
- package/lib/icons/DocumentTsIcon/index.js +6 -0
- package/lib/icons/DocumentYamlIcon/DocumentYamlIcon.d.ts +9 -0
- package/lib/icons/DocumentYamlIcon/DocumentYamlIcon.js +23 -0
- package/lib/icons/DocumentYamlIcon/index.d.ts +1 -0
- package/lib/icons/DocumentYamlIcon/index.js +6 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/layouts/CodeWalkthroughLayout.d.ts +5 -0
- package/lib/layouts/CodeWalkthroughLayout.js +72 -0
- package/lib/markdoc/attributes/code-walkthrough-filesets.d.ts +5 -0
- package/lib/markdoc/attributes/code-walkthrough-filesets.js +16 -0
- package/lib/markdoc/attributes/code-walkthrough-filters.d.ts +5 -0
- package/lib/markdoc/attributes/code-walkthrough-filters.js +16 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeContainer.d.ts +5 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeContainer.js +81 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeFilters.d.ts +12 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeFilters.js +58 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanel.d.ts +8 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanel.js +64 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelHeader.d.ts +8 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelHeader.js +155 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelPreview.d.ts +2 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelPreview.js +73 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelToolbar.d.ts +5 -0
- package/lib/markdoc/components/CodeWalkthrough/CodePanelToolbar.js +47 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeStep.d.ts +12 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeStep.js +128 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeToggle.d.ts +9 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeToggle.js +69 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeWalkthrough.d.ts +4 -0
- package/lib/markdoc/components/CodeWalkthrough/CodeWalkthrough.js +121 -0
- package/lib/markdoc/components/CodeWalkthrough/Input.d.ts +8 -0
- package/lib/markdoc/components/CodeWalkthrough/Input.js +99 -0
- package/lib/markdoc/components/CodeWalkthrough/variables.d.ts +1 -0
- package/lib/markdoc/components/CodeWalkthrough/variables.js +19 -0
- package/lib/markdoc/components/Image/Image.d.ts +7 -0
- package/lib/markdoc/components/Image/Image.js +45 -0
- package/lib/markdoc/components/default.d.ts +6 -0
- package/lib/markdoc/components/default.js +6 -0
- package/lib/markdoc/default.js +10 -0
- package/lib/markdoc/tags/code-step.d.ts +2 -0
- package/lib/markdoc/tags/code-step.js +28 -0
- package/lib/markdoc/tags/code-toggle.d.ts +2 -0
- package/lib/markdoc/tags/code-toggle.js +40 -0
- package/lib/markdoc/tags/code-walkthrough.d.ts +8 -0
- package/lib/markdoc/tags/code-walkthrough.js +242 -0
- package/lib/markdoc/tags/img.d.ts +2 -0
- package/lib/markdoc/tags/img.js +48 -0
- package/lib/markdoc/tags/input.d.ts +2 -0
- package/lib/markdoc/tags/input.js +37 -0
- package/lib/plugin.d.ts +2 -1
- package/lib/plugin.js +2 -4
- package/package.json +10 -3
- package/src/components/Buttons/CopyButton.tsx +24 -6
- package/src/components/Image/Image.tsx +21 -2
- package/src/components/Image/__tests__/images/test-image.png +0 -0
- package/src/components/Search/SearchAiResponse.tsx +1 -1
- package/src/components/Search/SearchDialog.tsx +5 -4
- package/src/components/StatusCode/StatusCode.ts +11 -10
- package/src/core/constants/code-walkthrough.ts +1 -0
- package/src/core/constants/index.ts +1 -0
- package/src/core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext.tsx +21 -0
- package/src/core/contexts/CodeWalkthrough/CodeWalkthroughStepsContext.tsx +10 -0
- package/src/core/contexts/index.ts +2 -0
- package/src/core/hooks/code-walkthrough/__mocks__/MockIntersectionObserver.ts +22 -0
- package/src/core/hooks/code-walkthrough/use-code-panel.ts +164 -0
- package/src/core/hooks/code-walkthrough/use-code-walkthrough-controls.ts +302 -0
- package/src/core/hooks/code-walkthrough/use-code-walkthrough-steps.ts +165 -0
- package/src/core/hooks/code-walkthrough/use-code-walkthrough.ts +51 -0
- package/src/core/hooks/index.ts +4 -0
- package/src/core/styles/global.ts +24 -10
- package/src/core/templates/Markdown.tsx +16 -5
- package/src/core/types/hooks.ts +2 -0
- package/src/core/types/l10n.ts +3 -1
- package/src/core/utils/download-code-walkthrough.ts +25 -0
- package/src/core/utils/get-code-walkthrough-file-text.ts +32 -0
- package/src/core/utils/get-file-icon.ts +35 -0
- package/src/core/utils/index.ts +5 -0
- package/src/core/utils/js-utils.ts +48 -0
- package/src/core/utils/match-code-walkthrough-conditions.ts +29 -0
- package/src/core/utils/replace-inputs-with-value.ts +11 -0
- package/src/icons/DocumentCssIcon/DocumentCssIcon.tsx +36 -0
- package/src/icons/DocumentCssIcon/index.ts +1 -0
- package/src/icons/DocumentGraphqlIcon/DocumentGraphqlIcon.tsx +64 -0
- package/src/icons/DocumentGraphqlIcon/index.ts +1 -0
- package/src/icons/DocumentHtmlIcon/DocumentHtmlIcon.tsx +36 -0
- package/src/icons/DocumentHtmlIcon/index.ts +1 -0
- package/src/icons/DocumentJsIcon/DocumentJsIcon.tsx +36 -0
- package/src/icons/DocumentJsIcon/index.ts +1 -0
- package/src/icons/DocumentJsonIcon/DocumentJsonIcon.tsx +36 -0
- package/src/icons/DocumentJsonIcon/index.ts +1 -0
- package/src/icons/DocumentMarkdownIcon/DocumentMarkdownIcon.tsx +36 -0
- package/src/icons/DocumentMarkdownIcon/index.ts +1 -0
- package/src/icons/DocumentReactIcon/DocumentReactIcon.tsx +36 -0
- package/src/icons/DocumentReactIcon/index.ts +1 -0
- package/src/icons/DocumentTsIcon/DocumentTsIcon.tsx +38 -0
- package/src/icons/DocumentTsIcon/index.ts +1 -0
- package/src/icons/DocumentYamlIcon/DocumentYamlIcon.tsx +36 -0
- package/src/icons/DocumentYamlIcon/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/layouts/CodeWalkthroughLayout.tsx +78 -0
- package/src/markdoc/attributes/code-walkthrough-filesets.ts +9 -0
- package/src/markdoc/attributes/code-walkthrough-filters.ts +9 -0
- package/src/markdoc/components/CodeWalkthrough/CodeContainer.tsx +76 -0
- package/src/markdoc/components/CodeWalkthrough/CodeFilters.tsx +87 -0
- package/src/markdoc/components/CodeWalkthrough/CodePanel.tsx +68 -0
- package/src/markdoc/components/CodeWalkthrough/CodePanelHeader.tsx +192 -0
- package/src/markdoc/components/CodeWalkthrough/CodePanelPreview.tsx +53 -0
- package/src/markdoc/components/CodeWalkthrough/CodePanelToolbar.tsx +31 -0
- package/src/markdoc/components/CodeWalkthrough/CodeStep.tsx +149 -0
- package/src/markdoc/components/CodeWalkthrough/CodeToggle.tsx +63 -0
- package/src/markdoc/components/CodeWalkthrough/CodeWalkthrough.tsx +111 -0
- package/src/markdoc/components/CodeWalkthrough/Input.tsx +101 -0
- package/src/markdoc/components/CodeWalkthrough/variables.ts +16 -0
- package/src/markdoc/components/Image/Image.tsx +38 -0
- package/src/markdoc/components/default.ts +6 -0
- package/src/markdoc/default.ts +10 -0
- package/src/markdoc/tags/code-step.ts +27 -0
- package/src/markdoc/tags/code-toggle.ts +37 -0
- package/src/markdoc/tags/code-walkthrough.ts +315 -0
- package/src/markdoc/tags/img.ts +46 -0
- package/src/markdoc/tags/input.ts +35 -0
- package/src/plugin.js +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { TooltipProps } from '../../components/Tooltip/Tooltip';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ButtonProps } from '../../components/Button/Button';
|
|
4
4
|
export type CopyButtonProps = {
|
|
5
5
|
data: unknown;
|
|
6
|
-
type?:
|
|
6
|
+
type?: 'icon' | 'text' | 'compound';
|
|
7
7
|
toasterPlacement?: TooltipProps['placement'];
|
|
8
8
|
toasterText?: string;
|
|
9
9
|
toasterDuration?: number;
|
|
@@ -11,6 +11,11 @@ export type CopyButtonProps = {
|
|
|
11
11
|
onCopyClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
12
12
|
dataTestId?: string;
|
|
13
13
|
className?: string;
|
|
14
|
-
variant?:
|
|
14
|
+
variant?: ButtonProps['variant'];
|
|
15
|
+
size?: ButtonProps['size'];
|
|
16
|
+
disabled?: ButtonProps['disabled'];
|
|
17
|
+
fullWidth?: ButtonProps['fullWidth'];
|
|
18
|
+
tone?: ButtonProps['tone'];
|
|
19
|
+
extraClass?: ButtonProps['extraClass'];
|
|
15
20
|
};
|
|
16
21
|
export declare const CopyButton: React.NamedExoticComponent<CopyButtonProps>;
|
|
@@ -30,7 +30,7 @@ const hooks_1 = require("../../core/hooks");
|
|
|
30
30
|
const Button_1 = require("../../components/Button/Button");
|
|
31
31
|
const CopyIcon_1 = require("../../icons/CopyIcon/CopyIcon");
|
|
32
32
|
const Tooltip_1 = require("../../components/Tooltip/Tooltip");
|
|
33
|
-
function CopyButtonComponent({ data, type = 'icon', toasterPlacement = 'top', toasterText, toasterDuration, buttonText, onCopyClick, dataTestId = 'copy-button', className, variant = 'text', }) {
|
|
33
|
+
function CopyButtonComponent({ data, type = 'icon', toasterPlacement = 'top', toasterText, toasterDuration, buttonText, onCopyClick, dataTestId = 'copy-button', className, variant = 'text', size = 'small', disabled, fullWidth, tone, extraClass, }) {
|
|
34
34
|
const { useTranslate } = (0, hooks_1.useThemeHooks)();
|
|
35
35
|
const tooltip = (0, hooks_1.useControl)();
|
|
36
36
|
const { translate } = useTranslate();
|
|
@@ -46,8 +46,9 @@ function CopyButtonComponent({ data, type = 'icon', toasterPlacement = 'top', to
|
|
|
46
46
|
showTooltip(duration);
|
|
47
47
|
onCopyClick === null || onCopyClick === void 0 ? void 0 : onCopyClick(e);
|
|
48
48
|
};
|
|
49
|
-
return (react_1.default.createElement(Tooltip_1.Tooltip, { className: `copy-button ${className ? className : ''}`, tip: translate('codeSnippet.copy.buttonText', toasterText || 'Copied!'), isOpen: tooltip.isOpened, placement: toasterPlacement },
|
|
50
|
-
react_1.default.createElement(Button_1.Button, { "data-component-name": "Buttons/CopyButton", onClick: (e) => copy(e, toasterDuration), "data-testid": dataTestId, icon: type === 'icon' ? react_1.default.createElement(CopyIcon_1.CopyIcon, null) : undefined, size:
|
|
49
|
+
return (react_1.default.createElement(Tooltip_1.Tooltip, { className: `copy-button ${className ? className : ''}`, tip: translate('codeSnippet.copy.buttonText', toasterText || 'Copied!'), isOpen: tooltip.isOpened, placement: toasterPlacement, width: "fit-content" },
|
|
50
|
+
react_1.default.createElement(Button_1.Button, { "data-component-name": "Buttons/CopyButton", onClick: (e) => copy(e, toasterDuration), "data-testid": dataTestId, icon: type === 'icon' || type === 'compound' ? react_1.default.createElement(CopyIcon_1.CopyIcon, null) : undefined, size: size, variant: variant, disabled: disabled, fullWidth: fullWidth, tone: tone, extraClass: extraClass }, (type === 'text' || type === 'compound') &&
|
|
51
|
+
translate('codeSnippet.copy.toasterText', buttonText || 'Copy'))));
|
|
51
52
|
}
|
|
52
53
|
exports.CopyButton = (0, react_1.memo)(CopyButtonComponent);
|
|
53
54
|
//# sourceMappingURL=CopyButton.js.map
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export type ImageProps = {
|
|
2
3
|
src?: string;
|
|
3
4
|
srcSet?: string;
|
|
4
5
|
alt?: string;
|
|
5
6
|
className?: string;
|
|
7
|
+
width?: string | number;
|
|
8
|
+
height?: string | number;
|
|
9
|
+
border?: string;
|
|
10
|
+
style?: React.CSSProperties | string;
|
|
6
11
|
};
|
|
7
12
|
export declare function Image(props: ImageProps): JSX.Element;
|
|
@@ -8,11 +8,12 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
9
|
const utils_1 = require("../../core/utils");
|
|
10
10
|
function Image(props) {
|
|
11
|
-
const { src, srcSet, alt, className } = props;
|
|
11
|
+
const { src, srcSet, alt, className, width, height, border, style } = props;
|
|
12
12
|
const parsedSourceSetMap = react_1.default.useMemo(() => {
|
|
13
13
|
return srcSet ? (0, utils_1.parseSrcSet)(srcSet) : new Map();
|
|
14
14
|
}, [srcSet]);
|
|
15
|
-
|
|
15
|
+
const combinedStyle = Object.assign(Object.assign({}, (border && { border })), (typeof style === 'string' ? { cssText: style } : style));
|
|
16
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, src ? (react_1.default.createElement("img", { src: src, alt: alt, className: className, width: width, height: height, style: combinedStyle })) : (Array.from(parsedSourceSetMap).map(([key, value]) => (react_1.default.createElement(ColorModeAwareImage, { key: key, colorMode: key, src: value, alt: alt, className: className, width: width, height: height, style: combinedStyle }))))));
|
|
16
17
|
}
|
|
17
18
|
const ColorModeAwareImage = styled_components_1.default.img `
|
|
18
19
|
html:not(.${(props) => props.colorMode}) && {
|
|
@@ -30,7 +30,7 @@ function SearchAiResponse(props) {
|
|
|
30
30
|
resources.length,
|
|
31
31
|
" ",
|
|
32
32
|
translate('search.ai.resourcesFound', 'resources found')),
|
|
33
|
-
react_1.default.createElement(ResourceTags, null, resources.map((resource, idx) => (react_1.default.createElement(Link_1.Link, { key: idx, to: resource.url },
|
|
33
|
+
react_1.default.createElement(ResourceTags, null, resources.map((resource, idx) => (react_1.default.createElement(Link_1.Link, { key: idx, to: resource.url, target: "_blank" },
|
|
34
34
|
react_1.default.createElement(ResourceTag, { borderless: true, icon: react_1.default.createElement(DocumentIcon_1.DocumentIcon, { color: "--search-ai-resource-tag-icon-color" }) }, resource.title))))))) : null)));
|
|
35
35
|
}
|
|
36
36
|
const ResponseWrapper = styled_components_1.default.div `
|
|
@@ -107,17 +107,19 @@ function SearchDialog({ onClose, className }) {
|
|
|
107
107
|
react_1.default.createElement(CloseIcon_1.CloseIcon, { onClick: () => setProduct(undefined), color: "--icon-color-additional" })))),
|
|
108
108
|
react_1.default.createElement(SearchInput_1.SearchInput, { value: query, onChange: setQuery, placeholder: mode === 'search'
|
|
109
109
|
? translate('search.label', 'Search docs...')
|
|
110
|
-
: translate('search.ai.label', 'Ask
|
|
110
|
+
: translate('search.ai.label', 'Ask AI assistant'), isLoading: isSearchLoading, showReturnButton: mode === 'ai-dialog', onReturn: () => setMode('search'), onSubmit: mode === 'ai-dialog'
|
|
111
111
|
? () => {
|
|
112
112
|
setQuery('');
|
|
113
113
|
aiSearch.askQuestion(query);
|
|
114
114
|
}
|
|
115
115
|
: undefined, "data-translation-key": mode === 'search' ? 'search.label' : 'search.ai.label' }),
|
|
116
116
|
showHeaderButtons && (react_1.default.createElement(SearchHeaderButtons, null,
|
|
117
|
-
showAiSearchButton ? (react_1.default.createElement(SearchAiButton, {
|
|
117
|
+
showAiSearchButton ? (react_1.default.createElement(SearchAiButton, { icon: react_1.default.createElement(AiStarsIcon_1.AiStarsIcon, null), onClick: () => {
|
|
118
118
|
setMode('ai-dialog');
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
if (query.trim()) {
|
|
120
|
+
setQuery('');
|
|
121
|
+
aiSearch.askQuestion(query);
|
|
122
|
+
}
|
|
121
123
|
} }, translate('search.aiButton', 'Search with AI'))) : null,
|
|
122
124
|
showSearchFilterButton && (react_1.default.createElement(SearchFilterToggleButton, { icon: react_1.default.createElement(SettingsIcon_1.SettingsIcon, null), onClick: onFilterToggle }))))),
|
|
123
125
|
react_1.default.createElement(SearchDialogBody, null, mode === 'search' ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -20,20 +20,17 @@ exports.StatusCode = styled_components_1.default.button.attrs({ 'data-component-
|
|
|
20
20
|
width: var(--status-code-width);
|
|
21
21
|
border: var(--status-code-border);
|
|
22
22
|
background-color: ${({ status }) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return 'var(--status-code-100-bg-color)';
|
|
23
|
+
switch (true) {
|
|
24
|
+
case status.startsWith('2'):
|
|
25
|
+
return 'var(--status-code-200-bg-color)';
|
|
26
|
+
case status.startsWith('3'):
|
|
27
|
+
return 'var(--status-code-300-bg-color)';
|
|
28
|
+
case status.startsWith('4'):
|
|
29
|
+
return 'var(--status-code-400-bg-color)';
|
|
30
|
+
case status.startsWith('5'):
|
|
31
|
+
return 'var(--status-code-500-bg-color)';
|
|
32
|
+
default:
|
|
33
|
+
return 'var(--status-code-100-bg-color)';
|
|
37
34
|
}
|
|
38
35
|
}}
|
|
39
36
|
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ACTIVE_STEP_QUERY_PARAM = "__step";
|
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("../../core/constants/common"), exports);
|
|
18
18
|
__exportStar(require("../../core/constants/environments"), exports);
|
|
19
|
+
__exportStar(require("../../core/constants/code-walkthrough"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeWalkthroughControlsStateContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.CodeWalkthroughControlsStateContext = (0, react_1.createContext)({
|
|
6
|
+
activeFilters: [],
|
|
7
|
+
getToggleState: () => null,
|
|
8
|
+
changeToggleState: () => { },
|
|
9
|
+
getInputState: () => null,
|
|
10
|
+
changeInputState: () => { },
|
|
11
|
+
getFilterState: () => null,
|
|
12
|
+
changeFilterState: () => { },
|
|
13
|
+
getFileText: () => '',
|
|
14
|
+
areConditionsMet: () => false,
|
|
15
|
+
handleDownloadCode: () => Promise.resolve(),
|
|
16
|
+
populateInputsWithValue: (node) => node,
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=CodeWalkthroughControlsContext.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeWalkthroughStepsContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.CodeWalkthroughStepsContext = (0, react_1.createContext)({
|
|
6
|
+
activeStep: null,
|
|
7
|
+
setActiveStep: () => { },
|
|
8
|
+
register: () => { },
|
|
9
|
+
unregister: () => { },
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=CodeWalkthroughStepsContext.js.map
|
|
@@ -15,4 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("../../core/contexts/ThemeDataContext"), exports);
|
|
18
|
+
__exportStar(require("../../core/contexts/CodeWalkthrough/CodeWalkthroughControlsContext"), exports);
|
|
19
|
+
__exportStar(require("../../core/contexts/CodeWalkthrough/CodeWalkthroughStepsContext"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class MockIntersectionObserver {
|
|
2
|
+
readonly root: Element | Document | null;
|
|
3
|
+
readonly rootMargin: string;
|
|
4
|
+
readonly thresholds: ReadonlyArray<number>;
|
|
5
|
+
observe: (target: HTMLElement) => void;
|
|
6
|
+
unobserve: (target: HTMLElement) => void;
|
|
7
|
+
disconnect: () => void;
|
|
8
|
+
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit);
|
|
9
|
+
takeRecords(): any[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MockIntersectionObserver = void 0;
|
|
4
|
+
class MockIntersectionObserver {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
constructor(callback, options) {
|
|
7
|
+
Object.defineProperty(this, "root", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "rootMargin", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "thresholds", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "observe", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "unobserve", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "disconnect", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
this.root = null;
|
|
44
|
+
this.rootMargin = '0px';
|
|
45
|
+
this.thresholds = [1];
|
|
46
|
+
this.observe = jest.fn;
|
|
47
|
+
this.unobserve = jest.fn;
|
|
48
|
+
this.disconnect = jest.fn;
|
|
49
|
+
}
|
|
50
|
+
takeRecords() {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.MockIntersectionObserver = MockIntersectionObserver;
|
|
55
|
+
//# sourceMappingURL=MockIntersectionObserver.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCodePanel = useCodePanel;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const contexts_1 = require("../../../core/contexts");
|
|
6
|
+
const hooks_1 = require("../../../core/hooks");
|
|
7
|
+
const ACTIVE_FILE_MOCK = {
|
|
8
|
+
content: [],
|
|
9
|
+
path: '',
|
|
10
|
+
basename: '',
|
|
11
|
+
metadata: {},
|
|
12
|
+
language: '',
|
|
13
|
+
};
|
|
14
|
+
function useCodePanel(files) {
|
|
15
|
+
const { activeStep } = (0, react_1.useContext)(contexts_1.CodeWalkthroughStepsContext);
|
|
16
|
+
const { areConditionsMet, populateInputsWithValue } = (0, react_1.useContext)(contexts_1.CodeWalkthroughControlsStateContext);
|
|
17
|
+
const { useCodeHighlight } = (0, hooks_1.useThemeHooks)();
|
|
18
|
+
const { highlight } = useCodeHighlight();
|
|
19
|
+
const findFileIndexByName = (0, react_1.useCallback)((name) => {
|
|
20
|
+
return files.findIndex((file) => file.path === name);
|
|
21
|
+
}, [files]);
|
|
22
|
+
const findFileIndexByStepId = (0, react_1.useCallback)((id) => files.findIndex((file) => file.metadata.steps.includes(id)), [files]);
|
|
23
|
+
const activeStepFileIndex = activeStep ? findFileIndexByStepId(activeStep) : 0;
|
|
24
|
+
const initialActiveFileIndex = activeStepFileIndex !== -1 ? activeStepFileIndex : 0;
|
|
25
|
+
const [activeFileIndex, setActiveFileIndex] = (0, react_1.useState)(initialActiveFileIndex);
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
setActiveFileIndex(initialActiveFileIndex);
|
|
28
|
+
}, [initialActiveFileIndex, activeStep, files]);
|
|
29
|
+
const handleTabSwitch = (0, react_1.useCallback)((name) => {
|
|
30
|
+
const index = findFileIndexByName(name);
|
|
31
|
+
if (index !== -1) {
|
|
32
|
+
setActiveFileIndex(index);
|
|
33
|
+
}
|
|
34
|
+
}, [findFileIndexByName]);
|
|
35
|
+
const activeFile = files[activeFileIndex] ||
|
|
36
|
+
// Fallback to default. Needed when switching from language with more files to a language with less files
|
|
37
|
+
files[initialActiveFileIndex] ||
|
|
38
|
+
// Final fallback for dev mode when no files were added yet
|
|
39
|
+
ACTIVE_FILE_MOCK;
|
|
40
|
+
const highlightedCode = (0, react_1.useMemo)(() => {
|
|
41
|
+
const { highlightedLines, code, isWholeFileSelected } = getRenderableCode(activeFile, activeStep, areConditionsMet, populateInputsWithValue);
|
|
42
|
+
return highlight(code, activeFile.language, {
|
|
43
|
+
withLineNumbers: true,
|
|
44
|
+
// Shiki transformerMetaHighlight meta to highlight lines
|
|
45
|
+
// If the whole file is selected for a step, do not apply highlighting
|
|
46
|
+
highlight: isWholeFileSelected ? '' : `{${Array.from(highlightedLines).join(',')}}`,
|
|
47
|
+
customTransformer: {
|
|
48
|
+
// Add greyed-out class to lines that are not highlighted
|
|
49
|
+
line(hast, number) {
|
|
50
|
+
if (!highlightedLines.has(number)) {
|
|
51
|
+
this.addClassToHast(hast, 'greyed-out');
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}, [activeFile, activeStep, highlight, areConditionsMet, populateInputsWithValue]);
|
|
57
|
+
return { activeFile, handleTabSwitch, highlightedCode };
|
|
58
|
+
}
|
|
59
|
+
function getRenderableCode(activeFile, activeStep, areConditionsMet, populateInputsWithValue) {
|
|
60
|
+
const codeLines = activeFile.content.flatMap((node) => getCodeLinesFromNode(node, activeStep, areConditionsMet, populateInputsWithValue));
|
|
61
|
+
const codeLinesContent = [];
|
|
62
|
+
const highlightedLines = new Set();
|
|
63
|
+
codeLines.forEach(({ lineContent, highlighted }, idx) => {
|
|
64
|
+
codeLinesContent.push(lineContent);
|
|
65
|
+
if (highlighted) {
|
|
66
|
+
highlightedLines.add(idx + 1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
highlightedLines,
|
|
71
|
+
code: codeLinesContent.join('\n'),
|
|
72
|
+
isWholeFileSelected: highlightedLines.size === codeLinesContent.length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert code node to code line objects with content to render and their highlighted status
|
|
77
|
+
*/
|
|
78
|
+
function getCodeLinesFromNode(node, activeStep, areConditionsMet, populateInputsWithValue, parentHighlighted = false) {
|
|
79
|
+
if (typeof node === 'string') {
|
|
80
|
+
const replacedNode = populateInputsWithValue(node);
|
|
81
|
+
return [{ lineContent: replacedNode, highlighted: parentHighlighted }];
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const shouldRenderChunk = areConditionsMet(node.condition);
|
|
85
|
+
const isHighlighted = activeStep != null &&
|
|
86
|
+
node.condition.steps.length > 0 &&
|
|
87
|
+
node.condition.steps.includes(activeStep);
|
|
88
|
+
return shouldRenderChunk
|
|
89
|
+
? node.children.flatMap((child) => getCodeLinesFromNode(child, activeStep, areConditionsMet, populateInputsWithValue, isHighlighted))
|
|
90
|
+
: [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=use-code-panel.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CodeWalkthroughFile, CodeWalkthroughFilter, InputsMarkdocAttr, TogglesMarkdocAttr, CodeWalkthroughFilterItem, ControlState, ControlTypeValue, ControlType, CodeWalkthroughConditionsObject } from '@redocly/config';
|
|
2
|
+
export type getState<T extends ControlType> = (id: string) => Omit<ControlState<T>, 'type'> | null;
|
|
3
|
+
export type changeState<T extends ControlType> = (id: string, value: ControlTypeValue<T>) => void;
|
|
4
|
+
export type ActiveFilter = {
|
|
5
|
+
id: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
items: CodeWalkthroughFilterItem[];
|
|
8
|
+
};
|
|
9
|
+
export type WalkthroughControlsState = {
|
|
10
|
+
activeFilters: ActiveFilter[];
|
|
11
|
+
getToggleState: getState<'toggle'>;
|
|
12
|
+
changeToggleState: changeState<'toggle'>;
|
|
13
|
+
getInputState: getState<'input'>;
|
|
14
|
+
changeInputState: changeState<'input'>;
|
|
15
|
+
getFilterState: getState<'filter'>;
|
|
16
|
+
changeFilterState: changeState<'filter'>;
|
|
17
|
+
areConditionsMet: (conditions: CodeWalkthroughConditionsObject) => boolean;
|
|
18
|
+
handleDownloadCode: (files: CodeWalkthroughFile[]) => Promise<void>;
|
|
19
|
+
getFileText: (file: CodeWalkthroughFile) => string;
|
|
20
|
+
populateInputsWithValue: (node: string) => string;
|
|
21
|
+
};
|
|
22
|
+
export declare function useCodeWalkthroughControls(filters: Record<string, CodeWalkthroughFilter>, inputs: InputsMarkdocAttr, toggles: TogglesMarkdocAttr): WalkthroughControlsState;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCodeWalkthroughControls = useCodeWalkthroughControls;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
6
|
+
const utils_1 = require("../../../core/utils");
|
|
7
|
+
const defaultControlsValues = {
|
|
8
|
+
input: '',
|
|
9
|
+
toggle: false,
|
|
10
|
+
filter: '',
|
|
11
|
+
};
|
|
12
|
+
function useCodeWalkthroughControls(filters, inputs, toggles) {
|
|
13
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
14
|
+
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
15
|
+
const searchParams = (0, react_1.useMemo)(() => new URLSearchParams(location.search), [location.search]);
|
|
16
|
+
const [togglesState, setTogglesState] = (0, react_1.useState)(() => {
|
|
17
|
+
const initialState = {};
|
|
18
|
+
for (const [id, toggle] of Object.entries(toggles)) {
|
|
19
|
+
initialState[id] = Object.assign(Object.assign({}, toggle), { render: true, type: 'toggle', value: searchParams.get(id) === 'true' });
|
|
20
|
+
}
|
|
21
|
+
return initialState;
|
|
22
|
+
});
|
|
23
|
+
const changeToggleState = (toggleId, checked) => {
|
|
24
|
+
setTogglesState((prev) => {
|
|
25
|
+
const toggle = prev[toggleId];
|
|
26
|
+
if (toggle) {
|
|
27
|
+
return Object.assign(Object.assign({}, prev), { [toggleId]: Object.assign(Object.assign({}, toggle), { value: checked }) });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return prev;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const getToggleState = (toggleId) => {
|
|
35
|
+
const toggleState = togglesState[toggleId];
|
|
36
|
+
if (toggleState) {
|
|
37
|
+
return {
|
|
38
|
+
render: toggleState.render,
|
|
39
|
+
value: toggleState.value,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const [inputsState, setInputsState] = (0, react_1.useState)(() => {
|
|
47
|
+
const initialState = {};
|
|
48
|
+
for (const [id, input] of Object.entries(inputs)) {
|
|
49
|
+
initialState[id] = Object.assign(Object.assign({}, input), { render: true, type: 'input', value: searchParams.get(id) || input.value });
|
|
50
|
+
}
|
|
51
|
+
return initialState;
|
|
52
|
+
});
|
|
53
|
+
const changeInputState = (inputId, value) => {
|
|
54
|
+
setInputsState((prev) => {
|
|
55
|
+
const input = prev[inputId];
|
|
56
|
+
if (input) {
|
|
57
|
+
return Object.assign(Object.assign({}, prev), { [inputId]: Object.assign(Object.assign({}, input), { value }) });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return prev;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const getInputState = (inputId) => {
|
|
65
|
+
const inputState = inputsState[inputId];
|
|
66
|
+
if (inputState) {
|
|
67
|
+
return {
|
|
68
|
+
render: inputState.render,
|
|
69
|
+
value: inputState.value,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const [filtersState, setFiltersState] = (0, react_1.useState)(() => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const initialState = {};
|
|
79
|
+
for (const [id, filter] of Object.entries(filters)) {
|
|
80
|
+
initialState[id] = Object.assign(Object.assign({}, filter), { render: true, type: 'filter', value: searchParams.get(id) || ((_b = (_a = filter === null || filter === void 0 ? void 0 : filter.items) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.value) || '' });
|
|
81
|
+
}
|
|
82
|
+
return initialState;
|
|
83
|
+
});
|
|
84
|
+
const changeFilterState = (filterId, value) => {
|
|
85
|
+
setFiltersState((prev) => {
|
|
86
|
+
const filter = prev[filterId];
|
|
87
|
+
if (filter) {
|
|
88
|
+
return Object.assign(Object.assign({}, prev), { [filterId]: Object.assign(Object.assign({}, filter), { value }) });
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return prev;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const getFilterState = (filterId) => {
|
|
96
|
+
const filterState = filtersState[filterId];
|
|
97
|
+
if (filterState) {
|
|
98
|
+
return {
|
|
99
|
+
render: filterState.render,
|
|
100
|
+
value: filterState.value,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const state = Object.assign(Object.assign(Object.assign({}, filtersState), togglesState), inputsState);
|
|
108
|
+
const walkthroughContext = (0, react_1.useMemo)(() => {
|
|
109
|
+
const areConditionsMet = (conditions) => (0, utils_1.matchCodeWalkthroughConditions)(conditions, state);
|
|
110
|
+
for (const [id, element] of Object.entries(state)) {
|
|
111
|
+
if (element && !areConditionsMet(element)) {
|
|
112
|
+
state[id].render = false;
|
|
113
|
+
state[id].value = defaultControlsValues[element.type];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const activeFilters = [];
|
|
117
|
+
for (const [id, filter] of Object.entries(filters)) {
|
|
118
|
+
if (!filtersState[id].render) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// code-walk-todo: need to check if we have a default fallback
|
|
122
|
+
const items = Array.isArray(filter === null || filter === void 0 ? void 0 : filter.items) ? filter.items : [];
|
|
123
|
+
const activeItems = items.filter((item) => areConditionsMet(item));
|
|
124
|
+
if (activeItems.length === 0) {
|
|
125
|
+
filtersState[id].render = false;
|
|
126
|
+
filtersState[id].value = defaultControlsValues['filter'];
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const currentValue = filtersState[id].value;
|
|
130
|
+
if (currentValue) {
|
|
131
|
+
const isValueInActiveItems = activeItems.findIndex(({ value }) => value === currentValue) !== -1;
|
|
132
|
+
filtersState[id].value = isValueInActiveItems ? currentValue : activeItems[0].value;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
filtersState[id].value = activeItems[0].value;
|
|
136
|
+
}
|
|
137
|
+
activeFilters.push({
|
|
138
|
+
id,
|
|
139
|
+
label: filter.label,
|
|
140
|
+
items: activeItems,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const handleDownloadCode = (files) => (0, utils_1.downloadCodeWalkthrough)(files, state, inputsState);
|
|
144
|
+
const getFileText = (file) => (0, utils_1.getCodeWalkthroughFileText)(file, state, inputsState);
|
|
145
|
+
const populateInputsWithValue = (node) => (0, utils_1.replaceInputsWithValue)(node, inputsState);
|
|
146
|
+
return {
|
|
147
|
+
activeFilters,
|
|
148
|
+
areConditionsMet,
|
|
149
|
+
handleDownloadCode,
|
|
150
|
+
getFileText,
|
|
151
|
+
populateInputsWithValue,
|
|
152
|
+
};
|
|
153
|
+
// Ignore state in dependency array as it's simply a combination of toggles, filters and inputs.
|
|
154
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
|
+
}, [filters, filtersState, togglesState, inputsState]);
|
|
156
|
+
/**
|
|
157
|
+
* Update the URL search params with the current state of the filters and inputs
|
|
158
|
+
*/
|
|
159
|
+
(0, react_1.useEffect)(() => {
|
|
160
|
+
const newSearchParams = new URLSearchParams(Array.from(searchParams.entries()));
|
|
161
|
+
for (const [id, { value }] of Object.entries(state)) {
|
|
162
|
+
if (value) {
|
|
163
|
+
newSearchParams.set(id, value.toString());
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
newSearchParams.delete(id);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const newSearch = newSearchParams.toString();
|
|
170
|
+
if (newSearch === location.search.substring(1))
|
|
171
|
+
return;
|
|
172
|
+
navigate({ search: newSearch });
|
|
173
|
+
// Ignore searchParams in dependency array to avoid infinite re-renders
|
|
174
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
175
|
+
}, [filters, filtersState, togglesState, inputsState, navigate, location, state]);
|
|
176
|
+
return Object.assign({ getInputState,
|
|
177
|
+
changeInputState,
|
|
178
|
+
getToggleState,
|
|
179
|
+
changeToggleState,
|
|
180
|
+
getFilterState,
|
|
181
|
+
changeFilterState }, walkthroughContext);
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=use-code-walkthrough-controls.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CodeWalkthroughStepAttr } from '@redocly/config';
|
|
2
|
+
type ActiveStep = string | null;
|
|
3
|
+
type CodeWalkthroughStep = CodeWalkthroughStepAttr & {
|
|
4
|
+
active?: boolean;
|
|
5
|
+
compRef?: HTMLElement;
|
|
6
|
+
};
|
|
7
|
+
export type WalkthroughStepsState = {
|
|
8
|
+
activeStep: ActiveStep;
|
|
9
|
+
setActiveStep: (stepId: ActiveStep) => void;
|
|
10
|
+
register: (element: HTMLElement) => void;
|
|
11
|
+
unregister: (element: HTMLElement) => void;
|
|
12
|
+
lockObserver?: React.MutableRefObject<boolean>;
|
|
13
|
+
filtersElementRef?: React.RefObject<HTMLDivElement>;
|
|
14
|
+
};
|
|
15
|
+
export declare function useCodeWalkthroughSteps(steps: CodeWalkthroughStep[]): WalkthroughStepsState;
|
|
16
|
+
export {};
|