@redocly/theme 0.47.0 → 0.48.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.
- package/lib/components/Buttons/CopyButton.d.ts +8 -3
- package/lib/components/Buttons/CopyButton.js +4 -3
- package/lib/components/Feedback/Mood.d.ts +2 -2
- package/lib/components/Feedback/Mood.js +6 -6
- package/lib/components/Feedback/Rating.d.ts +2 -2
- package/lib/components/Feedback/Rating.js +6 -6
- package/lib/components/Feedback/Scale.d.ts +2 -2
- package/lib/components/Feedback/Scale.js +6 -6
- package/lib/components/Feedback/Sentiment.d.ts +2 -2
- package/lib/components/Feedback/Sentiment.js +6 -6
- package/lib/components/Search/SearchDialog.js +8 -8
- package/lib/components/Search/SearchFilter.d.ts +3 -2
- package/lib/components/Search/SearchFilter.js +2 -2
- package/lib/components/Search/SearchFilterField.d.ts +3 -2
- package/lib/components/Search/SearchFilterField.js +2 -2
- package/lib/components/Search/SearchGroups.d.ts +5 -4
- package/lib/components/Search/SearchGroups.js +3 -3
- 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/__mocks__/search/use-search-filter.d.ts +1 -1
- package/lib/core/hooks/__mocks__/search/use-search-filter.js +1 -1
- 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/hooks/search/use-search-filter.d.ts +2 -2
- package/lib/core/hooks/search/use-search-filter.js +5 -5
- package/lib/core/styles/global.js +2 -0
- package/lib/core/templates/Markdown.d.ts +8 -2
- package/lib/core/templates/Markdown.js +5 -2
- package/lib/core/types/hooks.d.ts +3 -0
- package/lib/core/types/l10n.d.ts +1 -1
- package/lib/core/types/search.d.ts +1 -2
- 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/default.d.ts +5 -0
- package/lib/markdoc/components/default.js +5 -0
- package/lib/markdoc/default.js +8 -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/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/Feedback/Mood.tsx +9 -10
- package/src/components/Feedback/Rating.tsx +9 -10
- package/src/components/Feedback/Scale.tsx +9 -10
- package/src/components/Feedback/Sentiment.tsx +9 -10
- package/src/components/Search/SearchDialog.tsx +11 -6
- package/src/components/Search/SearchFilter.tsx +6 -3
- package/src/components/Search/SearchFilterField.tsx +4 -2
- package/src/components/Search/SearchGroups.tsx +13 -8
- 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/__mocks__/search/use-search-filter.ts +1 -1
- 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/hooks/search/use-search-filter.ts +9 -5
- package/src/core/styles/global.ts +2 -0
- package/src/core/templates/Markdown.tsx +16 -5
- package/src/core/types/hooks.ts +3 -0
- package/src/core/types/l10n.ts +5 -3
- package/src/core/types/search.ts +1 -2
- 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/default.ts +5 -0
- package/src/markdoc/default.ts +8 -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/input.ts +35 -0
- package/src/plugin.js +2 -2
|
@@ -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 {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCodeWalkthroughSteps = useCodeWalkthroughSteps;
|
|
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 constants_1 = require("../../../core/constants");
|
|
8
|
+
function useCodeWalkthroughSteps(steps) {
|
|
9
|
+
const location = (0, react_router_dom_1.useLocation)();
|
|
10
|
+
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
11
|
+
const searchParams = (0, react_1.useMemo)(() => new URLSearchParams(location.search), [location.search]);
|
|
12
|
+
const observerRef = (0, react_1.useRef)(null);
|
|
13
|
+
const filtersElementRef = (0, react_1.useRef)(null);
|
|
14
|
+
const lockObserver = (0, react_1.useRef)(false);
|
|
15
|
+
// Track observed elements in case new observer needs to be created
|
|
16
|
+
const observedElementsRef = (0, react_1.useRef)(new Set());
|
|
17
|
+
const [activeStep, setActiveStep] = (0, react_1.useState)(searchParams.get(constants_1.ACTIVE_STEP_QUERY_PARAM));
|
|
18
|
+
const register = (0, react_1.useCallback)((element) => {
|
|
19
|
+
// for some reason, the observer is not ready immediately
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
if (observerRef.current) {
|
|
22
|
+
const stepKey = Number(element.dataset.stepKey);
|
|
23
|
+
if (Number.isInteger(stepKey) && stepKey >= 0) {
|
|
24
|
+
steps[stepKey].compRef = element;
|
|
25
|
+
}
|
|
26
|
+
observerRef.current.observe(element);
|
|
27
|
+
observedElementsRef.current.add(element);
|
|
28
|
+
}
|
|
29
|
+
}, 10);
|
|
30
|
+
}, [steps]);
|
|
31
|
+
const unregister = (0, react_1.useCallback)((element) => {
|
|
32
|
+
if (observerRef.current) {
|
|
33
|
+
const stepKey = Number(element.dataset.stepKey);
|
|
34
|
+
if (Number.isInteger(stepKey) && stepKey >= 0) {
|
|
35
|
+
steps[stepKey].compRef = undefined;
|
|
36
|
+
}
|
|
37
|
+
observerRef.current.unobserve(element);
|
|
38
|
+
observedElementsRef.current.delete(element);
|
|
39
|
+
}
|
|
40
|
+
}, [steps]);
|
|
41
|
+
const observerCallback = (0, react_1.useCallback)((entries) => {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
if (lockObserver.current) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const stepsEntries = [];
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const { target } = entry;
|
|
49
|
+
const stepKey = Number((_a = target === null || target === void 0 ? void 0 : target.dataset) === null || _a === void 0 ? void 0 : _a.stepKey);
|
|
50
|
+
const stepActive = ((_b = target === null || target === void 0 ? void 0 : target.dataset) === null || _b === void 0 ? void 0 : _b.stepActive) === 'true';
|
|
51
|
+
if (!Number.isInteger(stepKey) || stepKey < 0) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const step = steps[stepKey];
|
|
55
|
+
step.active = stepActive;
|
|
56
|
+
stepsEntries.push(entry);
|
|
57
|
+
}
|
|
58
|
+
for (const stepEntry of stepsEntries) {
|
|
59
|
+
const { target, intersectionRatio, boundingClientRect, rootBounds, isIntersecting } = stepEntry;
|
|
60
|
+
const stepKey = Number((_c = target === null || target === void 0 ? void 0 : target.dataset) === null || _c === void 0 ? void 0 : _c.stepKey);
|
|
61
|
+
const step = steps[stepKey];
|
|
62
|
+
const renderedSteps = steps.filter((step) => Boolean(step.compRef));
|
|
63
|
+
const stepIndex = renderedSteps.findIndex((renderedStep) => renderedStep.stepKey === step.stepKey);
|
|
64
|
+
const { next } = (0, utils_1.getAdjacentValues)(renderedSteps, stepIndex);
|
|
65
|
+
const intersectionAtTop = (rootBounds === null || rootBounds === void 0 ? void 0 : rootBounds.bottom) !== undefined && boundingClientRect.top < rootBounds.top;
|
|
66
|
+
const stepGoesIn = isIntersecting;
|
|
67
|
+
if (intersectionRatio < 1 && intersectionRatio !== 0 && intersectionAtTop) {
|
|
68
|
+
let newStep = null;
|
|
69
|
+
if (stepGoesIn) {
|
|
70
|
+
newStep = step.id;
|
|
71
|
+
}
|
|
72
|
+
else if (next) {
|
|
73
|
+
newStep = next.id;
|
|
74
|
+
}
|
|
75
|
+
if (newStep !== activeStep) {
|
|
76
|
+
setActiveStep(newStep);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, [steps, activeStep]);
|
|
82
|
+
(0, react_1.useEffect)(() => {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
const filtersElementHeight = ((_a = filtersElementRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0;
|
|
85
|
+
const navbarHeight = ((_b = document.querySelector('nav')) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0;
|
|
86
|
+
const newObserver = new IntersectionObserver(observerCallback, {
|
|
87
|
+
threshold: [0.8],
|
|
88
|
+
rootMargin: `-${filtersElementHeight + navbarHeight}px 0px 0px 0px`,
|
|
89
|
+
});
|
|
90
|
+
for (const observedElement of observedElementsRef.current) {
|
|
91
|
+
newObserver.observe(observedElement);
|
|
92
|
+
}
|
|
93
|
+
// Unobserve all from the old observer
|
|
94
|
+
(_c = observerRef.current) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
95
|
+
observerRef.current = newObserver;
|
|
96
|
+
}, [observerCallback]);
|
|
97
|
+
/**
|
|
98
|
+
* Update the URL search params with the current state of the filters and inputs
|
|
99
|
+
*/
|
|
100
|
+
(0, react_1.useEffect)(() => {
|
|
101
|
+
const newSearchParams = new URLSearchParams(Array.from(searchParams.entries()));
|
|
102
|
+
if (activeStep) {
|
|
103
|
+
newSearchParams.set(constants_1.ACTIVE_STEP_QUERY_PARAM, activeStep);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
newSearchParams.delete(constants_1.ACTIVE_STEP_QUERY_PARAM);
|
|
107
|
+
}
|
|
108
|
+
const newSearch = newSearchParams.toString();
|
|
109
|
+
if (newSearch === location.search.substring(1))
|
|
110
|
+
return;
|
|
111
|
+
navigate({ search: newSearch });
|
|
112
|
+
// Ignore searchParams in dependency array to avoid infinite re-renders
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
}, [activeStep, navigate, location]);
|
|
115
|
+
return { register, unregister, lockObserver, filtersElementRef, activeStep, setActiveStep };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=use-code-walkthrough-steps.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CodeWalkthroughFileset, CodeWalkthroughFile, CodeWalkthroughStepAttr, CodeWalkthroughFilter, InputsMarkdocAttr, TogglesMarkdocAttr } from '@redocly/config';
|
|
2
|
+
import { type WalkthroughControlsState, type WalkthroughStepsState } from '../../../core/hooks';
|
|
3
|
+
export type WalkthroughState = {
|
|
4
|
+
stepsState: WalkthroughStepsState;
|
|
5
|
+
controlsState: WalkthroughControlsState;
|
|
6
|
+
downloadAssociatedFiles: CodeWalkthroughFile[];
|
|
7
|
+
files: CodeWalkthroughFile[];
|
|
8
|
+
};
|
|
9
|
+
export declare function useCodeWalkthrough(steps: CodeWalkthroughStepAttr[], attributes: {
|
|
10
|
+
filters: Record<string, CodeWalkthroughFilter>;
|
|
11
|
+
filesets: CodeWalkthroughFileset[];
|
|
12
|
+
inputs: InputsMarkdocAttr;
|
|
13
|
+
toggles: TogglesMarkdocAttr;
|
|
14
|
+
}): WalkthroughState;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCodeWalkthrough = useCodeWalkthrough;
|
|
4
|
+
const hooks_1 = require("../../../core/hooks");
|
|
5
|
+
function useCodeWalkthrough(steps, attributes) {
|
|
6
|
+
const { filters, filesets, inputs, toggles } = attributes;
|
|
7
|
+
const stepsState = (0, hooks_1.useCodeWalkthroughSteps)(steps);
|
|
8
|
+
const controlsState = (0, hooks_1.useCodeWalkthroughControls)(filters, inputs, toggles);
|
|
9
|
+
const files = filesets
|
|
10
|
+
.filter((fileset) => controlsState.areConditionsMet(fileset))
|
|
11
|
+
.flatMap((fileset) => fileset.files || []);
|
|
12
|
+
const downloadAssociatedFiles = filesets
|
|
13
|
+
.filter((fileset) => controlsState.areConditionsMet(fileset))
|
|
14
|
+
.flatMap((fileset) => fileset.downloadAssociatedFiles || []);
|
|
15
|
+
return {
|
|
16
|
+
stepsState,
|
|
17
|
+
controlsState,
|
|
18
|
+
downloadAssociatedFiles,
|
|
19
|
+
files,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=use-code-walkthrough.js.map
|
|
@@ -28,3 +28,7 @@ export * from '../../core/hooks/search/use-search-dialog';
|
|
|
28
28
|
export * from '../../core/hooks/search/use-search-filter';
|
|
29
29
|
export * from '../../core/hooks/use-controlled-state';
|
|
30
30
|
export * from '../../core/hooks/use-codeblock-tabs-controls';
|
|
31
|
+
export * from '../../core/hooks/code-walkthrough/use-code-walkthrough';
|
|
32
|
+
export * from '../../core/hooks/code-walkthrough/use-code-walkthrough-steps';
|
|
33
|
+
export * from '../../core/hooks/code-walkthrough/use-code-walkthrough-controls';
|
|
34
|
+
export * from '../../core/hooks/code-walkthrough/use-code-panel';
|
package/lib/core/hooks/index.js
CHANGED
|
@@ -44,4 +44,8 @@ __exportStar(require("../../core/hooks/search/use-search-dialog"), exports);
|
|
|
44
44
|
__exportStar(require("../../core/hooks/search/use-search-filter"), exports);
|
|
45
45
|
__exportStar(require("../../core/hooks/use-controlled-state"), exports);
|
|
46
46
|
__exportStar(require("../../core/hooks/use-codeblock-tabs-controls"), exports);
|
|
47
|
+
__exportStar(require("../../core/hooks/code-walkthrough/use-code-walkthrough"), exports);
|
|
48
|
+
__exportStar(require("../../core/hooks/code-walkthrough/use-code-walkthrough-steps"), exports);
|
|
49
|
+
__exportStar(require("../../core/hooks/code-walkthrough/use-code-walkthrough-controls"), exports);
|
|
50
|
+
__exportStar(require("../../core/hooks/code-walkthrough/use-code-panel"), exports);
|
|
47
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SearchFilterItem } from '../../../core/types';
|
|
2
2
|
export declare function useSearchFilter(filter: SearchFilterItem[], setFilter: React.Dispatch<React.SetStateAction<SearchFilterItem[]>>): {
|
|
3
3
|
onFacetReset: (field: string) => void;
|
|
4
|
-
|
|
5
|
-
onFilterChange: (field: string, value: string | string[] | undefined, isTop?: boolean) => void;
|
|
4
|
+
onFilterChange: (field: string, value: string | string[] | undefined, isQuickFilter?: boolean) => void;
|
|
6
5
|
onFilterReset: () => void;
|
|
7
6
|
onFilterToggle: () => void;
|
|
7
|
+
onQuickFilterReset: () => void;
|
|
8
8
|
isFilterOpen: boolean;
|
|
9
9
|
};
|
|
@@ -7,7 +7,7 @@ function useSearchFilter(filter, setFilter) {
|
|
|
7
7
|
const onFilterToggle = (0, react_1.useCallback)(() => {
|
|
8
8
|
setIsFilterOpen(!isFilterOpen);
|
|
9
9
|
}, [isFilterOpen]);
|
|
10
|
-
const onFilterChange = (field, value,
|
|
10
|
+
const onFilterChange = (field, value, isQuickFilter) => {
|
|
11
11
|
const values = value ? (Array.isArray(value) ? value : [value]) : [];
|
|
12
12
|
const _filter = [...filter];
|
|
13
13
|
const fieldIndex = _filter.findIndex((filter) => filter.field === field);
|
|
@@ -18,16 +18,16 @@ function useSearchFilter(filter, setFilter) {
|
|
|
18
18
|
else {
|
|
19
19
|
if (!values.length)
|
|
20
20
|
return;
|
|
21
|
-
_filter.push({ field, values,
|
|
21
|
+
_filter.push({ field, values, isQuickFilter });
|
|
22
22
|
}
|
|
23
23
|
setFilter(_filter.filter((item) => item.values.length));
|
|
24
24
|
};
|
|
25
25
|
const onFilterReset = () => {
|
|
26
26
|
setFilter([]);
|
|
27
27
|
};
|
|
28
|
-
const
|
|
28
|
+
const onQuickFilterReset = () => {
|
|
29
29
|
const _filter = [...filter];
|
|
30
|
-
setFilter(_filter.filter((item) => !item.
|
|
30
|
+
setFilter(_filter.filter((item) => !item.isQuickFilter));
|
|
31
31
|
};
|
|
32
32
|
const onFacetReset = (field) => {
|
|
33
33
|
const _filter = [...filter];
|
|
@@ -39,10 +39,10 @@ function useSearchFilter(filter, setFilter) {
|
|
|
39
39
|
};
|
|
40
40
|
return {
|
|
41
41
|
onFacetReset,
|
|
42
|
-
onTopFacetsReset,
|
|
43
42
|
onFilterChange,
|
|
44
43
|
onFilterReset,
|
|
45
44
|
onFilterToggle,
|
|
45
|
+
onQuickFilterReset,
|
|
46
46
|
isFilterOpen,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -38,6 +38,7 @@ const variables_32 = require("../../components/VersionPicker/variables");
|
|
|
38
38
|
const variables_33 = require("../../components/DatePicker/variables");
|
|
39
39
|
const variables_34 = require("../../components/Switch/variables");
|
|
40
40
|
const variables_35 = require("../../markdoc/components/Cards/variables");
|
|
41
|
+
const variables_36 = require("../../markdoc/components/CodeWalkthrough/variables");
|
|
41
42
|
const themeColors = (0, styled_components_1.css) `
|
|
42
43
|
/* === Palette === */
|
|
43
44
|
/**
|
|
@@ -1152,6 +1153,7 @@ exports.styles = (0, styled_components_1.css) `
|
|
|
1152
1153
|
${variables_35.cards}
|
|
1153
1154
|
${variables_8.catalog}
|
|
1154
1155
|
${variables_21.code}
|
|
1156
|
+
${variables_36.codeWalkthrough}
|
|
1155
1157
|
${docsDropdown}
|
|
1156
1158
|
${variables_12.dropdown}
|
|
1157
1159
|
${error}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { UiAccessibleConfig } from '../../config';
|
|
3
3
|
import type { MdHeading } from '../../core/types';
|
|
4
|
-
type MarkdownTemplateProps = {
|
|
4
|
+
export type MarkdownTemplateProps = {
|
|
5
5
|
pageProps: {
|
|
6
6
|
frontmatter?: UiAccessibleConfig;
|
|
7
7
|
headings?: (MdHeading | null)[];
|
|
@@ -9,7 +9,13 @@ type MarkdownTemplateProps = {
|
|
|
9
9
|
to: string;
|
|
10
10
|
};
|
|
11
11
|
lastModified?: string | null;
|
|
12
|
+
metadata: {
|
|
13
|
+
markdoc: {
|
|
14
|
+
tagList: string[];
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
12
19
|
};
|
|
13
20
|
};
|
|
14
21
|
export default function ({ pageProps, children }: React.PropsWithChildren<MarkdownTemplateProps>): React.JSX.Element;
|
|
15
|
-
export {};
|
|
@@ -32,6 +32,7 @@ const Markdown_1 = require("../../components/Markdown/Markdown");
|
|
|
32
32
|
const TableOfContent_1 = require("../../components/TableOfContent/TableOfContent");
|
|
33
33
|
const Feedback_1 = require("../../components/Feedback/Feedback");
|
|
34
34
|
const utils_1 = require("../../core/utils");
|
|
35
|
+
const CodeWalkthroughLayout_1 = require("../../layouts/CodeWalkthroughLayout");
|
|
35
36
|
function default_1({ pageProps, children }) {
|
|
36
37
|
var _a;
|
|
37
38
|
const [wrapperElement, setWrapperElement] = React.useState(null);
|
|
@@ -63,7 +64,9 @@ function default_1({ pageProps, children }) {
|
|
|
63
64
|
if (utils_1.IS_BROWSER) {
|
|
64
65
|
(0, utils_1.onDocumentReady)(utils_1.extendDetailsBehaviour);
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const document = React.createElement(Markdown_1.Markdown, { ref: wrapperRefCb }, children);
|
|
68
|
+
const tagList = pageProps.metadata.markdoc.tagList;
|
|
69
|
+
const withCodeWalkthrough = Boolean(Array.isArray(tagList) && tagList.includes('code-walkthrough'));
|
|
70
|
+
return withCodeWalkthrough ? (React.createElement(CodeWalkthroughLayout_1.CodeWalkthroughLayout, null, document)) : (React.createElement(DocumentationLayout_1.DocumentationLayout, Object.assign({}, documentationLayoutProps), document));
|
|
68
71
|
}
|
|
69
72
|
//# sourceMappingURL=Markdown.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageProps, ResolvedNavItemWithLink, Version } from '@redocly/config';
|
|
2
|
+
import type { ShikiTransformer } from '@shikijs/types';
|
|
2
3
|
import type { Callback, TFunction as TFunc } from 'i18next';
|
|
3
4
|
import type { To, Location, NavigateFunction } from 'react-router-dom';
|
|
4
5
|
import type { CatalogConfig, ProductUiConfig } from '../../config';
|
|
@@ -53,6 +54,7 @@ export type ThemeHooks = {
|
|
|
53
54
|
items: Record<string, SearchItemData[] | null>;
|
|
54
55
|
isSearchLoading: boolean;
|
|
55
56
|
facets: SearchFacet[];
|
|
57
|
+
groupField: string;
|
|
56
58
|
setLoadMore: React.Dispatch<React.SetStateAction<{
|
|
57
59
|
groupKey: string;
|
|
58
60
|
offset: number;
|
|
@@ -103,6 +105,7 @@ export type ThemeHooks = {
|
|
|
103
105
|
withLineNumbers?: boolean;
|
|
104
106
|
startLineNumber?: number;
|
|
105
107
|
highlight?: string;
|
|
108
|
+
customTransformer?: ShikiTransformer;
|
|
106
109
|
}) => string;
|
|
107
110
|
};
|
|
108
111
|
useLoadAndNavigate: () => (options: {
|