@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,242 @@
|
|
|
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.codeWalkthrough = void 0;
|
|
7
|
+
exports.collectStepsFromChildren = collectStepsFromChildren;
|
|
8
|
+
exports.collectTogglesFromChildren = collectTogglesFromChildren;
|
|
9
|
+
exports.collectInputsFromChildren = collectInputsFromChildren;
|
|
10
|
+
exports.validateCodeWalkthroughCondition = validateCodeWalkthroughCondition;
|
|
11
|
+
const markdoc_1 = __importDefault(require("@markdoc/markdoc"));
|
|
12
|
+
const code_walkthrough_filesets_1 = require("../../markdoc/attributes/code-walkthrough-filesets");
|
|
13
|
+
const code_walkthrough_filters_1 = require("../../markdoc/attributes/code-walkthrough-filters");
|
|
14
|
+
const utils_1 = require("../../core/utils");
|
|
15
|
+
exports.codeWalkthrough = {
|
|
16
|
+
tagName: 'code-walkthrough',
|
|
17
|
+
schema: {
|
|
18
|
+
attributes: {
|
|
19
|
+
filesets: {
|
|
20
|
+
type: code_walkthrough_filesets_1.CodeWalkthroughFilesets,
|
|
21
|
+
render: false,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
resolvedFilesets: {
|
|
25
|
+
type: Array,
|
|
26
|
+
render: false,
|
|
27
|
+
required: false,
|
|
28
|
+
},
|
|
29
|
+
filters: {
|
|
30
|
+
type: code_walkthrough_filters_1.CodeWalkthroughFilters,
|
|
31
|
+
render: false,
|
|
32
|
+
required: false,
|
|
33
|
+
},
|
|
34
|
+
inputs: {
|
|
35
|
+
type: Object,
|
|
36
|
+
render: false,
|
|
37
|
+
required: false,
|
|
38
|
+
},
|
|
39
|
+
toggles: {
|
|
40
|
+
type: Array,
|
|
41
|
+
render: false,
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
slots: {
|
|
46
|
+
preview: { required: false, render: true },
|
|
47
|
+
},
|
|
48
|
+
transform: (node, config) => {
|
|
49
|
+
const attributes = node.transformAttributes(config);
|
|
50
|
+
const children = node.transformChildren(config);
|
|
51
|
+
const steps = collectStepsFromChildren(children);
|
|
52
|
+
const inputs = collectInputsFromChildren(children);
|
|
53
|
+
const toggles = collectTogglesFromChildren(node.children);
|
|
54
|
+
return new markdoc_1.default.Tag('CodeWalkthrough', Object.assign(Object.assign({}, attributes), { filters: node.attributes.filters || {}, filesets: node.attributes.resolvedFilesets || [], steps: steps.map((step) => {
|
|
55
|
+
return Object.assign({}, ((step === null || step === void 0 ? void 0 : step.attributes) || {}));
|
|
56
|
+
}), inputs,
|
|
57
|
+
toggles }), children);
|
|
58
|
+
},
|
|
59
|
+
validate(node) {
|
|
60
|
+
const errors = [];
|
|
61
|
+
// code-walk-todo: validate when/unless for steps, toggles, inputs, and chunks
|
|
62
|
+
const toggleIds = Object.keys(collectTogglesFromChildren(node.children));
|
|
63
|
+
if ((0, utils_1.isObject)(node.attributes.filters)) {
|
|
64
|
+
Object.entries(node.attributes.filters).forEach(([id, filter]) => {
|
|
65
|
+
var _a;
|
|
66
|
+
if (!(0, utils_1.isObject)(filter)) {
|
|
67
|
+
errors.push({
|
|
68
|
+
id: 'filter-elements-type-invalid',
|
|
69
|
+
level: 'error',
|
|
70
|
+
message: 'The "filters" attribute elements must be of type object.',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (!((_a = filter.items) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
74
|
+
errors.push({
|
|
75
|
+
id: 'filter-required',
|
|
76
|
+
level: 'error',
|
|
77
|
+
message: `The "filters" items attribute for the filter ${id} should have at least one item.`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (node.attributes.filters) {
|
|
83
|
+
errors.push({
|
|
84
|
+
id: 'filter-type-invalid',
|
|
85
|
+
level: 'error',
|
|
86
|
+
message: 'The "filters" attribute must be of type object.',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(node.attributes.filesets)) {
|
|
90
|
+
node.attributes.filesets.forEach((fileset, idx) => {
|
|
91
|
+
if (fileset.when) {
|
|
92
|
+
const whenErrors = validateCodeWalkthroughCondition(fileset.when, node.attributes.filters || {}, toggleIds);
|
|
93
|
+
if (whenErrors.length > 0) {
|
|
94
|
+
errors.push({
|
|
95
|
+
id: 'fileset-when-invalid',
|
|
96
|
+
level: 'error',
|
|
97
|
+
message: `Invalid condition at 'filesets.${idx}.when':\n${whenErrors.join('\n')}`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (fileset.unless) {
|
|
102
|
+
const unlessErrors = validateCodeWalkthroughCondition(fileset.unless, node.attributes.filters || {}, toggleIds);
|
|
103
|
+
if (unlessErrors.length > 0) {
|
|
104
|
+
errors.push({
|
|
105
|
+
id: 'fileset-when-invalid',
|
|
106
|
+
level: 'error',
|
|
107
|
+
message: `Invalid condition at 'filesets.${idx}.unless':\n${unlessErrors.join('\n')}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (!node.attributes.filesets.length) {
|
|
113
|
+
errors.push({
|
|
114
|
+
id: 'filesets-required',
|
|
115
|
+
level: 'error',
|
|
116
|
+
message: 'The "filesets" attribute should have at least one item.',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
errors.push({
|
|
122
|
+
id: 'filesets-type-invalid',
|
|
123
|
+
level: 'error',
|
|
124
|
+
message: 'The "filesets" attribute must be of type array.',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
node.children.forEach((child) => {
|
|
128
|
+
if (child.tag === 'step') {
|
|
129
|
+
const isValidFilter = validateStepFilters(node.attributes.filters || {}, child.attributes);
|
|
130
|
+
if (!isValidFilter) {
|
|
131
|
+
errors.push({
|
|
132
|
+
id: 'step-filter-invalid',
|
|
133
|
+
level: 'error',
|
|
134
|
+
message: 'The "step" tag contains invalid filter attributes. Ensure "when" and "unless" conditions reference valid filters.',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return errors;
|
|
140
|
+
},
|
|
141
|
+
render: 'CodeWalkthrough',
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
function collectStepsFromChildren(children, idx = 0) {
|
|
145
|
+
return children.flatMap((child) => {
|
|
146
|
+
if (child instanceof markdoc_1.default.Tag && child.name === 'CodeStep') {
|
|
147
|
+
child.attributes.stepKey = idx++;
|
|
148
|
+
return [child];
|
|
149
|
+
}
|
|
150
|
+
if (child instanceof markdoc_1.default.Tag) {
|
|
151
|
+
return collectStepsFromChildren(child.children, idx);
|
|
152
|
+
}
|
|
153
|
+
return [];
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function collectTogglesFromChildren(children, toggles = {}) {
|
|
157
|
+
for (const child of children) {
|
|
158
|
+
if (child.tag === 'toggle') {
|
|
159
|
+
const id = child.attributes.id;
|
|
160
|
+
if (id) {
|
|
161
|
+
toggles[id] = {
|
|
162
|
+
when: child.attributes.when,
|
|
163
|
+
unless: child.attributes.unless,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
collectTogglesFromChildren(child.children, toggles);
|
|
168
|
+
}
|
|
169
|
+
return toggles;
|
|
170
|
+
}
|
|
171
|
+
function collectInputsFromChildren(children, inputs = {}) {
|
|
172
|
+
for (const child of children) {
|
|
173
|
+
if (child instanceof markdoc_1.default.Tag && child.name === 'Input') {
|
|
174
|
+
const id = child.attributes.id;
|
|
175
|
+
if (id) {
|
|
176
|
+
inputs[id] = {
|
|
177
|
+
value: child.attributes.value || '',
|
|
178
|
+
when: child.attributes.when,
|
|
179
|
+
unless: child.attributes.unless,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (child instanceof markdoc_1.default.Tag) {
|
|
185
|
+
collectInputsFromChildren(child.children, inputs);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return inputs;
|
|
189
|
+
}
|
|
190
|
+
function validateCodeWalkthroughCondition(conditions, filters, allToggles) {
|
|
191
|
+
var _a;
|
|
192
|
+
const errors = [];
|
|
193
|
+
for (const [filterId, filterValue] of Object.entries(conditions)) {
|
|
194
|
+
if (!filters[filterId] && !allToggles.includes(filterId)) {
|
|
195
|
+
errors.push('Unknown filter: ' + filterId);
|
|
196
|
+
}
|
|
197
|
+
else if (filterValue) {
|
|
198
|
+
const invalidFilterItems = getInvalidFilterValues(filterValue, ((_a = filters[filterId]) === null || _a === void 0 ? void 0 : _a.items) || []);
|
|
199
|
+
if (invalidFilterItems.length > 0) {
|
|
200
|
+
errors.push(`Filter item(s) are not defined on the filter '${filterId}': ${invalidFilterItems.join(', ')}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return errors;
|
|
205
|
+
}
|
|
206
|
+
function getInvalidFilterValues(filterConditionValue, definedValues) {
|
|
207
|
+
const togglesArray = Array.isArray(filterConditionValue)
|
|
208
|
+
? filterConditionValue
|
|
209
|
+
: [filterConditionValue];
|
|
210
|
+
const items = definedValues.map((item) => item.value);
|
|
211
|
+
return togglesArray.filter((toggle) => typeof toggle !== 'boolean' && !items.includes(toggle));
|
|
212
|
+
}
|
|
213
|
+
function validateStepFilters(filters, obj) {
|
|
214
|
+
function isValidFilter(filterKey, filterValue) {
|
|
215
|
+
if (!Object.prototype.hasOwnProperty.call(filters, filterKey)) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
const validItems = filters[filterKey].items.map((item) => item.value);
|
|
219
|
+
if (Array.isArray(filterValue)) {
|
|
220
|
+
return filterValue.every((value) => validItems.includes(value));
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
return validItems.includes(filterValue);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (obj.when) {
|
|
227
|
+
for (const [key, value] of Object.entries(obj.when)) {
|
|
228
|
+
if (!isValidFilter(key, value)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (obj.unless) {
|
|
234
|
+
for (const [key, value] of Object.entries(obj.unless)) {
|
|
235
|
+
if (!isValidFilter(key, value)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=code-walkthrough.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.input = void 0;
|
|
4
|
+
exports.input = {
|
|
5
|
+
tagName: 'input',
|
|
6
|
+
schema: {
|
|
7
|
+
attributes: {
|
|
8
|
+
id: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true,
|
|
11
|
+
},
|
|
12
|
+
label: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: false,
|
|
15
|
+
},
|
|
16
|
+
placeholder: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
value: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: false,
|
|
23
|
+
},
|
|
24
|
+
unless: {
|
|
25
|
+
type: Object,
|
|
26
|
+
required: false,
|
|
27
|
+
},
|
|
28
|
+
when: {
|
|
29
|
+
type: Object,
|
|
30
|
+
required: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
selfClosing: true,
|
|
34
|
+
render: 'Input',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=input.js.map
|
package/lib/plugin.d.ts
CHANGED
package/lib/plugin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/theme",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "Shared UI components lib",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@markdoc/markdoc": "0.4.0",
|
|
29
|
+
"lodash.debounce": "^4.0.8",
|
|
29
30
|
"lodash.throttle": "^4.1.1",
|
|
30
31
|
"react": "^17.0.0 || ^18.0.0",
|
|
31
32
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
@@ -35,16 +36,19 @@
|
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@markdoc/markdoc": "0.4.0",
|
|
39
|
+
"@shikijs/types": "1.24.2",
|
|
38
40
|
"@testing-library/jest-dom": "6.1.5",
|
|
39
41
|
"@testing-library/react": "14.1.2",
|
|
40
42
|
"@testing-library/user-event": "14.5.1",
|
|
43
|
+
"@types/file-saver": "2.0.7",
|
|
41
44
|
"@types/highlight-words-core": "1.2.3",
|
|
42
45
|
"@types/jest": "29.5.11",
|
|
43
46
|
"@types/jest-when": "3.5.5",
|
|
47
|
+
"@types/lodash.debounce": "4.0.9",
|
|
44
48
|
"@types/lodash.throttle": "4.1.9",
|
|
45
49
|
"@types/node": "18.19.3",
|
|
46
50
|
"@types/react": "18.3.9",
|
|
47
|
-
"@types/react-dom": "18.
|
|
51
|
+
"@types/react-dom": "18.3.5",
|
|
48
52
|
"@types/styled-components": "5.1.34",
|
|
49
53
|
"@types/styled-system": "5.1.22",
|
|
50
54
|
"@types/nprogress": "0.2.3",
|
|
@@ -54,6 +58,7 @@
|
|
|
54
58
|
"jest-styled-components": "7.2.0",
|
|
55
59
|
"jest-when": "3.6.0",
|
|
56
60
|
"json-schema-to-ts": "2.7.2",
|
|
61
|
+
"lodash.debounce": "4.0.8",
|
|
57
62
|
"lodash.throttle": "4.1.1",
|
|
58
63
|
"npm-run-all2": "5.0.2",
|
|
59
64
|
"react-refresh": "0.14.2",
|
|
@@ -72,8 +77,10 @@
|
|
|
72
77
|
},
|
|
73
78
|
"dependencies": {
|
|
74
79
|
"copy-to-clipboard": "3.3.3",
|
|
80
|
+
"file-saver": "2.0.5",
|
|
75
81
|
"highlight-words-core": "1.2.2",
|
|
76
82
|
"hotkeys-js": "3.10.1",
|
|
83
|
+
"jszip": "3.10.1",
|
|
77
84
|
"react-calendar": "4.2.1",
|
|
78
85
|
"react-date-picker": "10.0.3",
|
|
79
86
|
"timeago.js": "4.0.2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { memo } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { TooltipProps } from '@redocly/theme/components/Tooltip/Tooltip';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ButtonProps } from '@redocly/theme/components/Button/Button';
|
|
5
5
|
|
|
6
6
|
import { ClipboardService } from '@redocly/theme/core/utils';
|
|
7
7
|
import { useThemeHooks, useControl } from '@redocly/theme/core/hooks';
|
|
@@ -11,7 +11,7 @@ import { Tooltip } from '@redocly/theme/components/Tooltip/Tooltip';
|
|
|
11
11
|
|
|
12
12
|
export type CopyButtonProps = {
|
|
13
13
|
data: unknown;
|
|
14
|
-
type?:
|
|
14
|
+
type?: 'icon' | 'text' | 'compound';
|
|
15
15
|
toasterPlacement?: TooltipProps['placement'];
|
|
16
16
|
toasterText?: string;
|
|
17
17
|
toasterDuration?: number;
|
|
@@ -19,7 +19,14 @@ export type CopyButtonProps = {
|
|
|
19
19
|
onCopyClick?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
20
20
|
dataTestId?: string;
|
|
21
21
|
className?: string;
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
// Generic button props
|
|
24
|
+
variant?: ButtonProps['variant'];
|
|
25
|
+
size?: ButtonProps['size'];
|
|
26
|
+
disabled?: ButtonProps['disabled'];
|
|
27
|
+
fullWidth?: ButtonProps['fullWidth'];
|
|
28
|
+
tone?: ButtonProps['tone'];
|
|
29
|
+
extraClass?: ButtonProps['extraClass'];
|
|
23
30
|
};
|
|
24
31
|
|
|
25
32
|
function CopyButtonComponent({
|
|
@@ -33,6 +40,11 @@ function CopyButtonComponent({
|
|
|
33
40
|
dataTestId = 'copy-button',
|
|
34
41
|
className,
|
|
35
42
|
variant = 'text',
|
|
43
|
+
size = 'small',
|
|
44
|
+
disabled,
|
|
45
|
+
fullWidth,
|
|
46
|
+
tone,
|
|
47
|
+
extraClass,
|
|
36
48
|
}: CopyButtonProps): JSX.Element {
|
|
37
49
|
const { useTranslate } = useThemeHooks();
|
|
38
50
|
const tooltip = useControl();
|
|
@@ -59,16 +71,22 @@ function CopyButtonComponent({
|
|
|
59
71
|
tip={translate('codeSnippet.copy.buttonText', toasterText || 'Copied!')}
|
|
60
72
|
isOpen={tooltip.isOpened}
|
|
61
73
|
placement={toasterPlacement}
|
|
74
|
+
width="fit-content"
|
|
62
75
|
>
|
|
63
76
|
<Button
|
|
64
77
|
data-component-name="Buttons/CopyButton"
|
|
65
78
|
onClick={(e) => copy(e, toasterDuration)}
|
|
66
79
|
data-testid={dataTestId}
|
|
67
|
-
icon={type === 'icon' ? <CopyIcon /> : undefined}
|
|
68
|
-
size=
|
|
80
|
+
icon={type === 'icon' || type === 'compound' ? <CopyIcon /> : undefined}
|
|
81
|
+
size={size}
|
|
69
82
|
variant={variant}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
fullWidth={fullWidth}
|
|
85
|
+
tone={tone}
|
|
86
|
+
extraClass={extraClass}
|
|
70
87
|
>
|
|
71
|
-
{type
|
|
88
|
+
{(type === 'text' || type === 'compound') &&
|
|
89
|
+
translate('codeSnippet.copy.toasterText', buttonText || 'Copy')}
|
|
72
90
|
</Button>
|
|
73
91
|
</Tooltip>
|
|
74
92
|
);
|
|
@@ -17,16 +17,17 @@ export const StatusCode = styled.button.attrs({ 'data-component-name': 'StatusCo
|
|
|
17
17
|
width: var(--status-code-width);
|
|
18
18
|
border: var(--status-code-border);
|
|
19
19
|
background-color: ${({ status }) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
switch (true) {
|
|
21
|
+
case status.startsWith('2'):
|
|
22
|
+
return 'var(--status-code-200-bg-color)';
|
|
23
|
+
case status.startsWith('3'):
|
|
24
|
+
return 'var(--status-code-300-bg-color)';
|
|
25
|
+
case status.startsWith('4'):
|
|
26
|
+
return 'var(--status-code-400-bg-color)';
|
|
27
|
+
case status.startsWith('5'):
|
|
28
|
+
return 'var(--status-code-500-bg-color)';
|
|
29
|
+
default:
|
|
30
|
+
return 'var(--status-code-100-bg-color)';
|
|
30
31
|
}
|
|
31
32
|
}}
|
|
32
33
|
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ACTIVE_STEP_QUERY_PARAM = '__step';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { WalkthroughControlsState } from '@redocly/theme/core/hooks';
|
|
4
|
+
|
|
5
|
+
export const CodeWalkthroughControlsStateContext = createContext<WalkthroughControlsState>({
|
|
6
|
+
activeFilters: [],
|
|
7
|
+
|
|
8
|
+
getToggleState: () => null,
|
|
9
|
+
changeToggleState: () => {},
|
|
10
|
+
|
|
11
|
+
getInputState: () => null,
|
|
12
|
+
changeInputState: () => {},
|
|
13
|
+
|
|
14
|
+
getFilterState: () => null,
|
|
15
|
+
changeFilterState: () => {},
|
|
16
|
+
|
|
17
|
+
getFileText: () => '',
|
|
18
|
+
areConditionsMet: () => false,
|
|
19
|
+
handleDownloadCode: () => Promise.resolve(),
|
|
20
|
+
populateInputsWithValue: (node) => node,
|
|
21
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { WalkthroughStepsState } from '@redocly/theme/core/hooks';
|
|
4
|
+
|
|
5
|
+
export const CodeWalkthroughStepsContext = createContext<WalkthroughStepsState>({
|
|
6
|
+
activeStep: null,
|
|
7
|
+
setActiveStep: () => {},
|
|
8
|
+
register: () => {},
|
|
9
|
+
unregister: () => {},
|
|
10
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class MockIntersectionObserver {
|
|
2
|
+
public readonly root: Element | Document | null;
|
|
3
|
+
public readonly rootMargin: string;
|
|
4
|
+
public readonly thresholds: ReadonlyArray<number>;
|
|
5
|
+
observe: (target: HTMLElement) => void;
|
|
6
|
+
unobserve: (target: HTMLElement) => void;
|
|
7
|
+
disconnect: () => void;
|
|
8
|
+
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit) {
|
|
11
|
+
this.root = null;
|
|
12
|
+
this.rootMargin = '0px';
|
|
13
|
+
this.thresholds = [1];
|
|
14
|
+
this.observe = jest.fn;
|
|
15
|
+
this.unobserve = jest.fn;
|
|
16
|
+
this.disconnect = jest.fn;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
takeRecords(): any[] {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
}
|