@redocly/theme 0.47.0 → 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/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 +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 +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/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 +9 -2
- package/src/components/Buttons/CopyButton.tsx +24 -6
- 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 +2 -0
- 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/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,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
|
|
@@ -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';
|
|
@@ -103,6 +104,7 @@ export type ThemeHooks = {
|
|
|
103
104
|
withLineNumbers?: boolean;
|
|
104
105
|
startLineNumber?: number;
|
|
105
106
|
highlight?: string;
|
|
107
|
+
customTransformer?: ShikiTransformer;
|
|
106
108
|
}) => string;
|
|
107
109
|
};
|
|
108
110
|
useLoadAndNavigate: () => (options: {
|
package/lib/core/types/l10n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TOptions } from 'i18next';
|
|
2
|
-
export type TranslationKey = 'dev.newApp' | 'dev.newApp.text' | 'dev.sidebar.header' | 'dev.sidebar.footer.text' | 'dev.create.app.dialog.appName.placeholder' | 'dev.create.app.dialog.appName.error' | 'dev.create.app.dialog.selectAPIs' | 'dev.create.app.dialog.description' | 'dev.create.app.dialog.description.placeholder' | 'dev.create.app.dialog.create' | 'dev.create.app.dialog.cancel' | 'dev.main.tab.appKeys' | 'dev.main.tab.logs' | 'dev.app.description.title' | 'dev.edit.description.dialog.title' | 'dev.edit.description.dialog.save' | 'dev.edit.description.dialog.cancel' | 'dev.edit.apis.dialog.selectedAPIs' | 'dev.app.key.create' | 'dev.create.key.dialog.title' | 'dev.create.key.dialog.create' | 'dev.create.key.dialog.cancel' | 'dev.app.edit' | 'dev.app.delete' | 'dev.edit.app.dialog.title' | 'dev.edit.app.dialog.save' | 'dev.edit.app.dialog.cancel' | 'dev.delete.app.dialog.title' | 'dev.delete.app.dialog.confirmation' | 'dev.delete.app.dialog.delete' | 'dev.delete.app.dialog.cancel' | 'dev.app.key.roll' | 'dev.roll.key.dialog.title' | 'dev.roll.key.dialog.apiKey' | 'dev.roll.key.dialog.expires' | 'dev.roll.key.dialog.confirmation' | 'dev.roll.key.dialog.cancel' | 'dev.roll.key.dialog.roll' | 'dev.update.key.dialog.title' | 'dev.update.key.dialog.update' | 'dev.update.key.dialog.cancel' | 'dev.app.key.api.name' | 'dev.app.key.api.status' | 'dev.app.key.api.edit' | 'dev.edit.apis.dialog.title' | 'dev.edit.apis.dialog.apiKey' | 'dev.edit.apis.dialog.save' | 'dev.edit.apis.dialog.cancel' | 'dev.select.placeholder' | 'dev.app.overview.status.pending' | 'dev.app.overview.status.approved' | 'dev.app.overview.status.revoked' | 'dev.app.overview.status' | 'dev.app.overview.non-production' | 'dev.app.overview.production' | 'dev.app.overview.clientId' | 'dev.app.overview.apiKey' | 'dev.app.key.revoke' | 'dev.revoke.key.dialog.title' | 'dev.revoke.key.dialog.apiKey' | 'dev.revoke.key.dialog.expires' | 'dev.revoke.key.dialog.confirmation' | 'dev.revoke.key.dialog.revoke' | 'dev.revoke.key.dialog.cancel' | 'dev.app.overview.expires' | 'dev.app.overview.created' | 'dev.app.overview.visibilityToggle.hide' | 'dev.app.overview.visibilityToggle.show' | 'search.loading' | 'search.noResults.title' | 'search.keys.navigate' | 'search.keys.select' | 'search.keys.exit' | 'search.label' | 'search.cancel' | 'search.recent' | 'search.navbar.label' | 'search.suggested' | 'search.showMore' | 'search.filter.title' | 'search.filter.reset' | 'search.filter.field.reset' | 'search.ai.thinkingText' | 'search.ai.resourcesFound' | 'search.aiButton' | 'search.ai.label' | 'toc.header' | 'footer.copyrightText' | 'page.homeButton' | 'page.forbidden.title' | 'page.notFound.title' | 'page.notFound.description' | 'page.lastUpdated.timeago' | 'page.lastUpdated.on' | 'catalog.filters.placeholder' | 'catalog.filters.title' | 'catalog.filters.clearAll' | 'catalog.filters.select.addFilter' | 'catalog.filters.select.all' | 'catalog.filters.done' | 'sidebar.menu.backLabel' | 'sidebar.menu.backToLabel' | 'sidebar.actions.show' | 'sidebar.actions.hide' | 'sidebar.actions.changeLayout' | 'versionPicker.label' | 'versionPicker.unversioned' | 'codeSnippet.copy.buttonText' | 'codeSnippet.copy.tooltipText' | 'codeSnippet.copy.toasterText' | 'markdown.editPage.text' | 'feedback.settings.comment.submitText' | 'feedback.settings.comment.label' | 'feedback.settings.comment.send' | 'feedback.settings.comment.cancel' | 'feedback.settings.comment.satisfiedLabel' | 'feedback.settings.comment.neutralLabel' | 'feedback.settings.comment.dissatisfiedLabel' | 'feedback.settings.submitText' | 'feedback.settings.label' | 'feedback.settings.reasons.label' | 'feedback.settings.reasons.send' | 'feedback.settings.comment.likeLabel' | 'feedback.settings.comment.dislikeLabel' | 'feedback.sentiment.thumbUp' | 'feedback.sentiment.thumbDown' | 'feedback.settings.leftScaleLabel' | 'feedback.settings.rightScaleLabel' | 'feedback.settings.anonymousUserEmail.placeholder' | 'feedback.settings.anonymousUserEmail.label' | 'codeSnippet.report.buttonText' | 'codeSnippet.report.tooltipText' | 'codeSnippet.report.label' | 'userMenu.login' | 'userMenu.logout' | 'userMenu.devOnboardingLabel' | 'mobileMenu.mainMenu' | 'mobileMenu.previous' | 'mobileMenu.products' | 'page.nextButton' | 'page.previousButton' | 'openapi.download.description.title' | 'openapi.info.title' | 'openapi.info.contact.url' | 'openapi.info.contact.name' | 'openapi.info.license' | 'openapi.info.termsOfService' | 'openapi.info.metadata.title' | 'openapi.key' | 'openapi.value' | 'openapi.enum' | 'openapi.items' | 'openapi.default' | 'openapi.variable' | 'openapi.variables' | 'openapi.actions.show' | 'openapi.actions.hide' | 'openapi.actions.more' | 'openapi.languages.title' | 'openapi.servers.title' | 'openapi.operations' | 'openapi.webhooks' | 'openapi.description' | 'openapi.badges.deprecated' | 'openapi.badges.required' | 'openapi.badges.webhook' | 'openapi.request' | 'openapi.path' | 'openapi.query' | 'openapi.cookie' | 'openapi.header' | 'openapi.body' | 'openapi.responses' | 'openapi.response' | 'openapi.callbacks' | 'openapi.callbackRequest' | 'openapi.callbackResponse' | 'openapi.payload' | 'openapi.discriminator' | 'openapi.contentType' | 'openapi.tryIt' | 'openapi.loading' | 'openapi.example' | 'openapi.examples' | 'openapi.additionalProperties' | 'openapi.patternProperties' | 'openapi.required' | 'openapi.recursive' | 'openapi.complex' | 'openapi.deprecated' | 'openapi.hideExample' | 'openapi.showExample' | 'openapi.expandAll' | 'openapi.collapseAll' | 'openapi.noResponseExample' | 'openapi.noRequestPayload' | 'openapi.hidePattern' | 'openapi.showPattern' | 'openapi.authorizationUrl' | 'openapi.tokenUrl' | 'openapi.refreshUrl' | 'openapi.scopes' | 'openapi.security' | 'openapi.httpAuthorizationScheme' | 'openapi.bearerFormat' | 'openapi.parameterName' | 'openapi.flowType' | 'openapi.connectUrl' | 'openapi.requiredScopes' | 'openapi.unsupportedLanguage' | 'openapi.failedToGenerateCodeSample' | 'graphql.queries' | 'graphql.mutations' | 'graphql.subscriptions' | 'graphql.directives' | 'graphql.objects' | 'graphql.interfaces' | 'graphql.unions' | 'graphql.enums' | 'graphql.inputs' | 'graphql.scalars' | 'graphql.arguments.label' | 'graphql.arguments.show' | 'graphql.arguments.hide' | 'graphql.arguments.here' | 'graphql.returnTypes.label' | 'graphql.returnTypes.show' | 'graphql.returnTypes.hide' | 'graphql.possibleTypes' | 'graphql.defaultValue' | 'graphql.deprecationReason' | 'graphql.implementedInterfaces' | 'graphql.nonNull' | 'graphql.required' | 'graphql.deprecated' | 'graphql.variables' | 'graphql.querySample' | 'graphql.mutationSample' | 'graphql.subscriptionSample' | 'graphql.responseSample' | 'graphql.locations' | 'graphql.sample' | 'graphql.referenced';
|
|
2
|
+
export type TranslationKey = 'dev.newApp' | 'dev.newApp.text' | 'dev.sidebar.header' | 'dev.sidebar.footer.text' | 'dev.create.app.dialog.appName.placeholder' | 'dev.create.app.dialog.appName.error' | 'dev.create.app.dialog.selectAPIs' | 'dev.create.app.dialog.description' | 'dev.create.app.dialog.description.placeholder' | 'dev.create.app.dialog.create' | 'dev.create.app.dialog.cancel' | 'dev.main.tab.appKeys' | 'dev.main.tab.logs' | 'dev.app.description.title' | 'dev.edit.description.dialog.title' | 'dev.edit.description.dialog.save' | 'dev.edit.description.dialog.cancel' | 'dev.edit.apis.dialog.selectedAPIs' | 'dev.app.key.create' | 'dev.create.key.dialog.title' | 'dev.create.key.dialog.create' | 'dev.create.key.dialog.cancel' | 'dev.app.edit' | 'dev.app.delete' | 'dev.edit.app.dialog.title' | 'dev.edit.app.dialog.save' | 'dev.edit.app.dialog.cancel' | 'dev.delete.app.dialog.title' | 'dev.delete.app.dialog.confirmation' | 'dev.delete.app.dialog.delete' | 'dev.delete.app.dialog.cancel' | 'dev.app.key.roll' | 'dev.roll.key.dialog.title' | 'dev.roll.key.dialog.apiKey' | 'dev.roll.key.dialog.expires' | 'dev.roll.key.dialog.confirmation' | 'dev.roll.key.dialog.cancel' | 'dev.roll.key.dialog.roll' | 'dev.update.key.dialog.title' | 'dev.update.key.dialog.update' | 'dev.update.key.dialog.cancel' | 'dev.app.key.api.name' | 'dev.app.key.api.status' | 'dev.app.key.api.edit' | 'dev.edit.apis.dialog.title' | 'dev.edit.apis.dialog.apiKey' | 'dev.edit.apis.dialog.save' | 'dev.edit.apis.dialog.cancel' | 'dev.select.placeholder' | 'dev.app.overview.status.pending' | 'dev.app.overview.status.approved' | 'dev.app.overview.status.revoked' | 'dev.app.overview.status' | 'dev.app.overview.non-production' | 'dev.app.overview.production' | 'dev.app.overview.clientId' | 'dev.app.overview.apiKey' | 'dev.app.key.revoke' | 'dev.revoke.key.dialog.title' | 'dev.revoke.key.dialog.apiKey' | 'dev.revoke.key.dialog.expires' | 'dev.revoke.key.dialog.confirmation' | 'dev.revoke.key.dialog.revoke' | 'dev.revoke.key.dialog.cancel' | 'dev.app.overview.expires' | 'dev.app.overview.created' | 'dev.app.overview.visibilityToggle.hide' | 'dev.app.overview.visibilityToggle.show' | 'search.loading' | 'search.noResults.title' | 'search.keys.navigate' | 'search.keys.select' | 'search.keys.exit' | 'search.label' | 'search.cancel' | 'search.recent' | 'search.navbar.label' | 'search.suggested' | 'search.showMore' | 'search.filter.title' | 'search.filter.reset' | 'search.filter.field.reset' | 'search.ai.thinkingText' | 'search.ai.resourcesFound' | 'search.aiButton' | 'search.ai.label' | 'toc.header' | 'footer.copyrightText' | 'page.homeButton' | 'page.forbidden.title' | 'page.notFound.title' | 'page.notFound.description' | 'page.lastUpdated.timeago' | 'page.lastUpdated.on' | 'catalog.filters.placeholder' | 'catalog.filters.title' | 'catalog.filters.clearAll' | 'catalog.filters.select.addFilter' | 'catalog.filters.select.all' | 'catalog.filters.done' | 'sidebar.menu.backLabel' | 'sidebar.menu.backToLabel' | 'sidebar.actions.show' | 'sidebar.actions.hide' | 'sidebar.actions.changeLayout' | 'versionPicker.label' | 'versionPicker.unversioned' | 'codeSnippet.copy.buttonText' | 'codeSnippet.copy.tooltipText' | 'codeSnippet.copy.toasterText' | 'markdown.editPage.text' | 'feedback.settings.comment.submitText' | 'feedback.settings.comment.label' | 'feedback.settings.comment.send' | 'feedback.settings.comment.cancel' | 'feedback.settings.comment.satisfiedLabel' | 'feedback.settings.comment.neutralLabel' | 'feedback.settings.comment.dissatisfiedLabel' | 'feedback.settings.submitText' | 'feedback.settings.label' | 'feedback.settings.reasons.label' | 'feedback.settings.reasons.send' | 'feedback.settings.comment.likeLabel' | 'feedback.settings.comment.dislikeLabel' | 'feedback.sentiment.thumbUp' | 'feedback.sentiment.thumbDown' | 'feedback.settings.leftScaleLabel' | 'feedback.settings.rightScaleLabel' | 'feedback.settings.anonymousUserEmail.placeholder' | 'feedback.settings.anonymousUserEmail.label' | 'codeSnippet.report.buttonText' | 'codeSnippet.report.tooltipText' | 'codeSnippet.report.label' | 'userMenu.login' | 'userMenu.logout' | 'userMenu.devOnboardingLabel' | 'mobileMenu.mainMenu' | 'mobileMenu.previous' | 'mobileMenu.products' | 'page.nextButton' | 'page.previousButton' | 'openapi.download.description.title' | 'openapi.info.title' | 'openapi.info.contact.url' | 'openapi.info.contact.name' | 'openapi.info.license' | 'openapi.info.termsOfService' | 'openapi.info.metadata.title' | 'openapi.key' | 'openapi.value' | 'openapi.enum' | 'openapi.items' | 'openapi.default' | 'openapi.variable' | 'openapi.variables' | 'openapi.actions.show' | 'openapi.actions.hide' | 'openapi.actions.more' | 'openapi.languages.title' | 'openapi.servers.title' | 'openapi.operations' | 'openapi.webhooks' | 'openapi.description' | 'openapi.badges.deprecated' | 'openapi.badges.required' | 'openapi.badges.webhook' | 'openapi.request' | 'openapi.path' | 'openapi.query' | 'openapi.cookie' | 'openapi.header' | 'openapi.body' | 'openapi.responses' | 'openapi.response' | 'openapi.callbacks' | 'openapi.callbackRequest' | 'openapi.callbackResponse' | 'openapi.payload' | 'openapi.discriminator' | 'openapi.contentType' | 'openapi.tryIt' | 'openapi.loading' | 'openapi.example' | 'openapi.examples' | 'openapi.additionalProperties' | 'openapi.patternProperties' | 'openapi.required' | 'openapi.recursive' | 'openapi.complex' | 'openapi.deprecated' | 'openapi.hideExample' | 'openapi.showExample' | 'openapi.expandAll' | 'openapi.collapseAll' | 'openapi.noResponseExample' | 'openapi.noRequestPayload' | 'openapi.hidePattern' | 'openapi.showPattern' | 'openapi.authorizationUrl' | 'openapi.tokenUrl' | 'openapi.refreshUrl' | 'openapi.scopes' | 'openapi.security' | 'openapi.httpAuthorizationScheme' | 'openapi.bearerFormat' | 'openapi.parameterName' | 'openapi.flowType' | 'openapi.connectUrl' | 'openapi.requiredScopes' | 'openapi.unsupportedLanguage' | 'openapi.failedToGenerateCodeSample' | 'graphql.queries' | 'graphql.mutations' | 'graphql.subscriptions' | 'graphql.directives' | 'graphql.objects' | 'graphql.interfaces' | 'graphql.unions' | 'graphql.enums' | 'graphql.inputs' | 'graphql.scalars' | 'graphql.arguments.label' | 'graphql.arguments.show' | 'graphql.arguments.hide' | 'graphql.arguments.here' | 'graphql.returnTypes.label' | 'graphql.returnTypes.show' | 'graphql.returnTypes.hide' | 'graphql.possibleTypes' | 'graphql.defaultValue' | 'graphql.deprecationReason' | 'graphql.implementedInterfaces' | 'graphql.nonNull' | 'graphql.required' | 'graphql.deprecated' | 'graphql.variables' | 'graphql.querySample' | 'graphql.mutationSample' | 'graphql.subscriptionSample' | 'graphql.responseSample' | 'graphql.locations' | 'graphql.sample' | 'graphql.referenced' | 'codeWalkthrough.download' | 'codeWalkthrough.preview';
|
|
3
3
|
export type Locale = {
|
|
4
4
|
code: string;
|
|
5
5
|
name: string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.downloadCodeWalkthrough = downloadCodeWalkthrough;
|
|
16
|
+
const file_saver_1 = require("file-saver");
|
|
17
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
18
|
+
const utils_1 = require("../../core/utils");
|
|
19
|
+
// https://github.com/Stuk/jszip/issues/196#issuecomment-69503828
|
|
20
|
+
jszip_1.default.support.nodebuffer = false;
|
|
21
|
+
function downloadCodeWalkthrough(files, state, inputsState) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const zip = new jszip_1.default();
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
const fileContent = (0, utils_1.getCodeWalkthroughFileText)(file, state, inputsState);
|
|
26
|
+
zip.file(file.basename, fileContent);
|
|
27
|
+
}
|
|
28
|
+
const zipContent = yield zip.generateAsync({ type: 'blob' });
|
|
29
|
+
(0, file_saver_1.saveAs)(zipContent, 'sample-code.zip');
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=download-code-walkthrough.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCodeWalkthroughFileText = getCodeWalkthroughFileText;
|
|
4
|
+
const utils_1 = require("../../core/utils");
|
|
5
|
+
function getCodeWalkthroughFileText(file, state, inputsState) {
|
|
6
|
+
var _a;
|
|
7
|
+
const contentChunks = (_a = file === null || file === void 0 ? void 0 : file.content.flatMap((node) => getChunkText(node, state, inputsState))) !== null && _a !== void 0 ? _a : [];
|
|
8
|
+
return contentChunks.join('\n');
|
|
9
|
+
}
|
|
10
|
+
function getChunkText(node, state, inputsState) {
|
|
11
|
+
if (typeof node === 'string') {
|
|
12
|
+
const replacedNode = (0, utils_1.replaceInputsWithValue)(node, inputsState);
|
|
13
|
+
return [replacedNode];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
if (!(0, utils_1.matchCodeWalkthroughConditions)(node.condition || {}, state)) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return node.children.flatMap((child) => getChunkText(child, state, inputsState));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=get-code-walkthrough-file-text.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileIconByExt = getFileIconByExt;
|
|
4
|
+
const DocumentBlankIcon_1 = require("../../icons/DocumentBlankIcon/DocumentBlankIcon");
|
|
5
|
+
const DocumentYamlIcon_1 = require("../../icons/DocumentYamlIcon/DocumentYamlIcon");
|
|
6
|
+
const DocumentJsonIcon_1 = require("../../icons/DocumentJsonIcon/DocumentJsonIcon");
|
|
7
|
+
const DocumentJsIcon_1 = require("../../icons/DocumentJsIcon/DocumentJsIcon");
|
|
8
|
+
const DocumentTsIcon_1 = require("../../icons/DocumentTsIcon/DocumentTsIcon");
|
|
9
|
+
const DocumentCssIcon_1 = require("../../icons/DocumentCssIcon/DocumentCssIcon");
|
|
10
|
+
const DocumentHtmlIcon_1 = require("../../icons/DocumentHtmlIcon/DocumentHtmlIcon");
|
|
11
|
+
const DocumentReactIcon_1 = require("../../icons/DocumentReactIcon/DocumentReactIcon");
|
|
12
|
+
const DocumentMarkdownIcon_1 = require("../../icons/DocumentMarkdownIcon/DocumentMarkdownIcon");
|
|
13
|
+
const DocumentGraphqlIcon_1 = require("../../icons/DocumentGraphqlIcon/DocumentGraphqlIcon");
|
|
14
|
+
const fileIconMap = {
|
|
15
|
+
yaml: DocumentYamlIcon_1.DocumentYamlIcon,
|
|
16
|
+
yml: DocumentYamlIcon_1.DocumentYamlIcon,
|
|
17
|
+
json: DocumentJsonIcon_1.DocumentJsonIcon,
|
|
18
|
+
js: DocumentJsIcon_1.DocumentJsIcon,
|
|
19
|
+
ts: DocumentTsIcon_1.DocumentTsIcon,
|
|
20
|
+
css: DocumentCssIcon_1.DocumentCssIcon,
|
|
21
|
+
html: DocumentHtmlIcon_1.DocumentHtmlIcon,
|
|
22
|
+
jsx: DocumentReactIcon_1.DocumentReactIcon,
|
|
23
|
+
tsx: DocumentReactIcon_1.DocumentReactIcon,
|
|
24
|
+
md: DocumentMarkdownIcon_1.DocumentMarkdownIcon,
|
|
25
|
+
graphql: DocumentGraphqlIcon_1.DocumentGraphqlIcon,
|
|
26
|
+
gql: DocumentGraphqlIcon_1.DocumentGraphqlIcon,
|
|
27
|
+
};
|
|
28
|
+
function getFileIconByExt(ext) {
|
|
29
|
+
return fileIconMap[ext] || DocumentBlankIcon_1.DocumentBlankIcon;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=get-file-icon.js.map
|
|
@@ -25,3 +25,8 @@ export * from '../../core/utils/details';
|
|
|
25
25
|
export * from '../../core/utils/get-navbar-element';
|
|
26
26
|
export * from '../../core/utils/with-load-progress';
|
|
27
27
|
export * from '../../core/utils/text-trimmer';
|
|
28
|
+
export * from '../../core/utils/get-code-walkthrough-file-text';
|
|
29
|
+
export * from '../../core/utils/download-code-walkthrough';
|
|
30
|
+
export * from '../../core/utils/get-file-icon';
|
|
31
|
+
export * from '../../core/utils/match-code-walkthrough-conditions';
|
|
32
|
+
export * from '../../core/utils/replace-inputs-with-value';
|
package/lib/core/utils/index.js
CHANGED
|
@@ -41,4 +41,9 @@ __exportStar(require("../../core/utils/details"), exports);
|
|
|
41
41
|
__exportStar(require("../../core/utils/get-navbar-element"), exports);
|
|
42
42
|
__exportStar(require("../../core/utils/with-load-progress"), exports);
|
|
43
43
|
__exportStar(require("../../core/utils/text-trimmer"), exports);
|
|
44
|
+
__exportStar(require("../../core/utils/get-code-walkthrough-file-text"), exports);
|
|
45
|
+
__exportStar(require("../../core/utils/download-code-walkthrough"), exports);
|
|
46
|
+
__exportStar(require("../../core/utils/get-file-icon"), exports);
|
|
47
|
+
__exportStar(require("../../core/utils/match-code-walkthrough-conditions"), exports);
|
|
48
|
+
__exportStar(require("../../core/utils/replace-inputs-with-value"), exports);
|
|
44
49
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,3 +6,33 @@ export declare function toStringIfDefined(value: unknown): string | undefined;
|
|
|
6
6
|
* Returns true when the function executed in browser.
|
|
7
7
|
*/
|
|
8
8
|
export declare function isBrowser(): boolean;
|
|
9
|
+
export declare function isPlainObject(obj: any): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the previous and next values in an array for a given index.
|
|
12
|
+
*
|
|
13
|
+
* Edge cases:
|
|
14
|
+
* - If the index is `0`, `prev` will be `null`.
|
|
15
|
+
* - If the index is the last position in the array, `next` will be `null`.
|
|
16
|
+
* - If the index is out of bounds (negative or greater than the last index), both `prev` and `next` will be `null`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const array = [10, 20, 30, 40];
|
|
20
|
+
* getAdjacentValues(array, 2);
|
|
21
|
+
* // returns: { prev: 20, next: 40 }
|
|
22
|
+
*
|
|
23
|
+
* getAdjacentValues(array, 0);
|
|
24
|
+
* // returns: { prev: null, next: 20 }
|
|
25
|
+
*
|
|
26
|
+
* getAdjacentValues(array, 3);
|
|
27
|
+
* // returns: { prev: 30, next: null }
|
|
28
|
+
*
|
|
29
|
+
* getAdjacentValues(array, -1);
|
|
30
|
+
* // returns: { prev: null, next: null }
|
|
31
|
+
*
|
|
32
|
+
* getAdjacentValues(array, 4);
|
|
33
|
+
* // returns: { prev: null, next: null }
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAdjacentValues<T>(array: T[], index: number): {
|
|
36
|
+
prev: T | null;
|
|
37
|
+
next: T | null;
|
|
38
|
+
};
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findDeepFirst = findDeepFirst;
|
|
4
4
|
exports.toStringIfDefined = toStringIfDefined;
|
|
5
5
|
exports.isBrowser = isBrowser;
|
|
6
|
+
exports.isPlainObject = isPlainObject;
|
|
7
|
+
exports.getAdjacentValues = getAdjacentValues;
|
|
6
8
|
function findDeepFirst(list, cb) {
|
|
7
9
|
for (const item of list) {
|
|
8
10
|
if (cb(item) === true) {
|
|
@@ -24,4 +26,43 @@ function toStringIfDefined(value) {
|
|
|
24
26
|
function isBrowser() {
|
|
25
27
|
return typeof window !== 'undefined' && 'HTMLElement' in window;
|
|
26
28
|
}
|
|
29
|
+
function isPlainObject(obj) {
|
|
30
|
+
return (typeof obj === 'object' &&
|
|
31
|
+
obj !== null &&
|
|
32
|
+
!Array.isArray(obj) &&
|
|
33
|
+
Object.prototype.toString.call(obj) === '[object Object]');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the previous and next values in an array for a given index.
|
|
37
|
+
*
|
|
38
|
+
* Edge cases:
|
|
39
|
+
* - If the index is `0`, `prev` will be `null`.
|
|
40
|
+
* - If the index is the last position in the array, `next` will be `null`.
|
|
41
|
+
* - If the index is out of bounds (negative or greater than the last index), both `prev` and `next` will be `null`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const array = [10, 20, 30, 40];
|
|
45
|
+
* getAdjacentValues(array, 2);
|
|
46
|
+
* // returns: { prev: 20, next: 40 }
|
|
47
|
+
*
|
|
48
|
+
* getAdjacentValues(array, 0);
|
|
49
|
+
* // returns: { prev: null, next: 20 }
|
|
50
|
+
*
|
|
51
|
+
* getAdjacentValues(array, 3);
|
|
52
|
+
* // returns: { prev: 30, next: null }
|
|
53
|
+
*
|
|
54
|
+
* getAdjacentValues(array, -1);
|
|
55
|
+
* // returns: { prev: null, next: null }
|
|
56
|
+
*
|
|
57
|
+
* getAdjacentValues(array, 4);
|
|
58
|
+
* // returns: { prev: null, next: null }
|
|
59
|
+
*/
|
|
60
|
+
function getAdjacentValues(array, index) {
|
|
61
|
+
if (index < 0 || index >= array.length) {
|
|
62
|
+
return { prev: null, next: null };
|
|
63
|
+
}
|
|
64
|
+
const prevValue = index > 0 ? array[index - 1] : null;
|
|
65
|
+
const nextValue = index < array.length - 1 ? array[index + 1] : null;
|
|
66
|
+
return { prev: prevValue, next: nextValue };
|
|
67
|
+
}
|
|
27
68
|
//# sourceMappingURL=js-utils.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchCodeWalkthroughConditions = matchCodeWalkthroughConditions;
|
|
4
|
+
const utils_1 = require("../../core/utils");
|
|
5
|
+
function matchCodeWalkthroughConditions(conditions = {}, state) {
|
|
6
|
+
const { when, unless } = conditions;
|
|
7
|
+
function evaluateCondition(key, value) {
|
|
8
|
+
var _a;
|
|
9
|
+
const stateValue = (_a = state[key]) === null || _a === void 0 ? void 0 : _a.value;
|
|
10
|
+
if (Array.isArray(value) && typeof stateValue === 'string') {
|
|
11
|
+
return value.includes(stateValue);
|
|
12
|
+
}
|
|
13
|
+
return stateValue === value;
|
|
14
|
+
}
|
|
15
|
+
const matchesWhen = (0, utils_1.isObject)(when)
|
|
16
|
+
? Object.entries(when).every(([key, value]) => evaluateCondition(key, value))
|
|
17
|
+
: true;
|
|
18
|
+
const matchesUnless = (0, utils_1.isObject)(unless)
|
|
19
|
+
? Object.entries(unless).some(([key, value]) => evaluateCondition(key, value))
|
|
20
|
+
: false;
|
|
21
|
+
return matchesWhen && !matchesUnless;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=match-code-walkthrough-conditions.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceInputsWithValue = replaceInputsWithValue;
|
|
4
|
+
const inputRegex = /(?:\/\*|<!--|#|\/\/)\s*@redocly-input\s*\{"id":\s*"(.*?)"\}\s*(?:\*\/|-->)?/g;
|
|
5
|
+
function replaceInputsWithValue(node, inputs) {
|
|
6
|
+
return node.replace(inputRegex, (match, inputKey) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(inputs, inputKey)) {
|
|
9
|
+
return (_a = inputs[inputKey]) === null || _a === void 0 ? void 0 : _a.value;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return match;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=replace-inputs-with-value.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IconProps } from '../../icons/types';
|
|
3
|
+
export declare const DocumentCssIcon: import("styled-components").StyledComponent<(props: IconProps) => React.JSX.Element, any, {
|
|
4
|
+
'data-component-name': string;
|
|
5
|
+
} & {
|
|
6
|
+
color?: string;
|
|
7
|
+
size?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
} & React.SVGProps<SVGSVGElement>, "data-component-name">;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DocumentCssIcon = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
const utils_1 = require("../../core/utils");
|
|
10
|
+
const Icon = (props) => (react_1.default.createElement("svg", Object.assign({ width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, props),
|
|
11
|
+
react_1.default.createElement("g", { id: "iconCSS" },
|
|
12
|
+
react_1.default.createElement("path", { id: "Vector", d: "M3.33329 2L2.89996 4.22667H11.96L11.6666 5.66667H2.61329L2.17329 7.88667H11.2333L10.7266 10.4267L7.07329 11.6333L3.90662 10.4267L4.12662 9.33333H1.89996L1.37329 12L6.60662 14L12.64 12L13.44 7.98L13.6 7.17333L14.6266 2H3.33329Z", fill: "#3B3C45" }))));
|
|
13
|
+
exports.DocumentCssIcon = (0, styled_components_1.default)(Icon).attrs(() => ({
|
|
14
|
+
'data-component-name': 'icons/DocumentCssIcon/DocumentCssIcon',
|
|
15
|
+
})) `
|
|
16
|
+
path {
|
|
17
|
+
fill: ${({ color }) => (0, utils_1.getCssColorVariable)(color)};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
height: ${({ size }) => size || '16px'};
|
|
21
|
+
width: ${({ size }) => size || '16px'};
|
|
22
|
+
`;
|
|
23
|
+
//# sourceMappingURL=DocumentCssIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DocumentCssIcon } from '../../icons/DocumentCssIcon/DocumentCssIcon';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentCssIcon = void 0;
|
|
4
|
+
var DocumentCssIcon_1 = require("../../icons/DocumentCssIcon/DocumentCssIcon");
|
|
5
|
+
Object.defineProperty(exports, "DocumentCssIcon", { enumerable: true, get: function () { return DocumentCssIcon_1.DocumentCssIcon; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { IconProps } from '../../icons/types';
|
|
3
|
+
export declare const DocumentGraphqlIcon: import("styled-components").StyledComponent<(props: IconProps) => React.JSX.Element, any, {
|
|
4
|
+
'data-component-name': string;
|
|
5
|
+
} & {
|
|
6
|
+
color?: string;
|
|
7
|
+
size?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
} & React.SVGProps<SVGSVGElement>, "data-component-name">;
|