@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,315 @@
|
|
|
1
|
+
import markdoc, { Node, RenderableTreeNode, ValidationError } from '@markdoc/markdoc';
|
|
2
|
+
|
|
3
|
+
import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
|
|
4
|
+
import type {
|
|
5
|
+
CodeWalkthroughConditions,
|
|
6
|
+
CodeWalkthroughFileset,
|
|
7
|
+
CodeWalkthroughFilter,
|
|
8
|
+
CodeWalkthroughStepAttr,
|
|
9
|
+
CodeWalkthroughFilterItem,
|
|
10
|
+
TogglesMarkdocAttr,
|
|
11
|
+
InputsMarkdocAttr,
|
|
12
|
+
} from '@redocly/config';
|
|
13
|
+
|
|
14
|
+
import { CodeWalkthroughFilesets } from '@redocly/theme/markdoc/attributes/code-walkthrough-filesets';
|
|
15
|
+
import { CodeWalkthroughFilters } from '@redocly/theme/markdoc/attributes/code-walkthrough-filters';
|
|
16
|
+
import { isObject } from '@redocly/theme/core/utils';
|
|
17
|
+
|
|
18
|
+
export const codeWalkthrough: MarkdocSchemaWrapper = {
|
|
19
|
+
tagName: 'code-walkthrough',
|
|
20
|
+
schema: {
|
|
21
|
+
attributes: {
|
|
22
|
+
filesets: {
|
|
23
|
+
type: CodeWalkthroughFilesets,
|
|
24
|
+
render: false,
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
resolvedFilesets: {
|
|
28
|
+
type: Array,
|
|
29
|
+
render: false,
|
|
30
|
+
required: false,
|
|
31
|
+
},
|
|
32
|
+
filters: {
|
|
33
|
+
type: CodeWalkthroughFilters,
|
|
34
|
+
render: false,
|
|
35
|
+
required: false,
|
|
36
|
+
},
|
|
37
|
+
inputs: {
|
|
38
|
+
type: Object,
|
|
39
|
+
render: false,
|
|
40
|
+
required: false,
|
|
41
|
+
},
|
|
42
|
+
toggles: {
|
|
43
|
+
type: Array,
|
|
44
|
+
render: false,
|
|
45
|
+
required: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
slots: {
|
|
49
|
+
preview: { required: false, render: true },
|
|
50
|
+
},
|
|
51
|
+
transform: (node, config) => {
|
|
52
|
+
const attributes = node.transformAttributes(config);
|
|
53
|
+
const children = node.transformChildren(config);
|
|
54
|
+
const steps = collectStepsFromChildren(children);
|
|
55
|
+
const inputs = collectInputsFromChildren(children);
|
|
56
|
+
const toggles = collectTogglesFromChildren(node.children);
|
|
57
|
+
|
|
58
|
+
return new markdoc.Tag(
|
|
59
|
+
'CodeWalkthrough',
|
|
60
|
+
{
|
|
61
|
+
...attributes,
|
|
62
|
+
filters: node.attributes.filters || {},
|
|
63
|
+
filesets: node.attributes.resolvedFilesets || [],
|
|
64
|
+
steps: steps.map((step) => {
|
|
65
|
+
return {
|
|
66
|
+
...((step as any)?.attributes || {}),
|
|
67
|
+
} as CodeWalkthroughStepAttr;
|
|
68
|
+
}),
|
|
69
|
+
inputs,
|
|
70
|
+
toggles,
|
|
71
|
+
},
|
|
72
|
+
children,
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
validate(node) {
|
|
76
|
+
const errors: ValidationError[] = [];
|
|
77
|
+
// code-walk-todo: validate when/unless for steps, toggles, inputs, and chunks
|
|
78
|
+
|
|
79
|
+
const toggleIds = Object.keys(collectTogglesFromChildren(node.children));
|
|
80
|
+
|
|
81
|
+
if (isObject(node.attributes.filters)) {
|
|
82
|
+
Object.entries(node.attributes.filters).forEach(([id, filter]) => {
|
|
83
|
+
if (!isObject(filter)) {
|
|
84
|
+
errors.push({
|
|
85
|
+
id: 'filter-elements-type-invalid',
|
|
86
|
+
level: 'error' as const,
|
|
87
|
+
message: 'The "filters" attribute elements must be of type object.',
|
|
88
|
+
});
|
|
89
|
+
} else if (!(filter as CodeWalkthroughFilter).items?.length) {
|
|
90
|
+
errors.push({
|
|
91
|
+
id: 'filter-required',
|
|
92
|
+
level: 'error' as const,
|
|
93
|
+
message: `The "filters" items attribute for the filter ${id} should have at least one item.`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
} else if (node.attributes.filters) {
|
|
98
|
+
errors.push({
|
|
99
|
+
id: 'filter-type-invalid',
|
|
100
|
+
level: 'error' as const,
|
|
101
|
+
message: 'The "filters" attribute must be of type object.',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(node.attributes.filesets)) {
|
|
106
|
+
node.attributes.filesets.forEach((fileset: CodeWalkthroughFileset, idx) => {
|
|
107
|
+
if (fileset.when) {
|
|
108
|
+
const whenErrors = validateCodeWalkthroughCondition(
|
|
109
|
+
fileset.when,
|
|
110
|
+
node.attributes.filters || {},
|
|
111
|
+
toggleIds,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
if (whenErrors.length > 0) {
|
|
115
|
+
errors.push({
|
|
116
|
+
id: 'fileset-when-invalid',
|
|
117
|
+
level: 'error' as const,
|
|
118
|
+
message: `Invalid condition at 'filesets.${idx}.when':\n${whenErrors.join('\n')}`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (fileset.unless) {
|
|
124
|
+
const unlessErrors = validateCodeWalkthroughCondition(
|
|
125
|
+
fileset.unless,
|
|
126
|
+
node.attributes.filters || {},
|
|
127
|
+
toggleIds,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
if (unlessErrors.length > 0) {
|
|
131
|
+
errors.push({
|
|
132
|
+
id: 'fileset-when-invalid',
|
|
133
|
+
level: 'error' as const,
|
|
134
|
+
message: `Invalid condition at 'filesets.${idx}.unless':\n${unlessErrors.join('\n')}`,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (!node.attributes.filesets.length) {
|
|
141
|
+
errors.push({
|
|
142
|
+
id: 'filesets-required',
|
|
143
|
+
level: 'error' as const,
|
|
144
|
+
message: 'The "filesets" attribute should have at least one item.',
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
errors.push({
|
|
149
|
+
id: 'filesets-type-invalid',
|
|
150
|
+
level: 'error' as const,
|
|
151
|
+
message: 'The "filesets" attribute must be of type array.',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
node.children.forEach((child) => {
|
|
156
|
+
if (child.tag === 'step') {
|
|
157
|
+
const isValidFilter = validateStepFilters(
|
|
158
|
+
node.attributes.filters || {},
|
|
159
|
+
child.attributes,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
if (!isValidFilter) {
|
|
163
|
+
errors.push({
|
|
164
|
+
id: 'step-filter-invalid',
|
|
165
|
+
level: 'error' as const,
|
|
166
|
+
message:
|
|
167
|
+
'The "step" tag contains invalid filter attributes. Ensure "when" and "unless" conditions reference valid filters.',
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return errors;
|
|
174
|
+
},
|
|
175
|
+
render: 'CodeWalkthrough',
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export function collectStepsFromChildren(
|
|
180
|
+
children: RenderableTreeNode[],
|
|
181
|
+
idx = 0,
|
|
182
|
+
): RenderableTreeNode[] {
|
|
183
|
+
return children.flatMap((child) => {
|
|
184
|
+
if (child instanceof markdoc.Tag && child.name === 'CodeStep') {
|
|
185
|
+
child.attributes.stepKey = idx++;
|
|
186
|
+
return [child];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (child instanceof markdoc.Tag) {
|
|
190
|
+
return collectStepsFromChildren(child.children, idx);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return [];
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function collectTogglesFromChildren(
|
|
198
|
+
children: Node[],
|
|
199
|
+
toggles: TogglesMarkdocAttr = {},
|
|
200
|
+
): TogglesMarkdocAttr {
|
|
201
|
+
for (const child of children) {
|
|
202
|
+
if (child.tag === 'toggle') {
|
|
203
|
+
const id = child.attributes.id as string;
|
|
204
|
+
if (id) {
|
|
205
|
+
toggles[id] = {
|
|
206
|
+
when: child.attributes.when,
|
|
207
|
+
unless: child.attributes.unless,
|
|
208
|
+
} as TogglesMarkdocAttr;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
collectTogglesFromChildren(child.children, toggles);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return toggles;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function collectInputsFromChildren(
|
|
219
|
+
children: RenderableTreeNode[],
|
|
220
|
+
inputs: InputsMarkdocAttr = {},
|
|
221
|
+
): InputsMarkdocAttr {
|
|
222
|
+
for (const child of children) {
|
|
223
|
+
if (child instanceof markdoc.Tag && child.name === 'Input') {
|
|
224
|
+
const id = child.attributes.id as string;
|
|
225
|
+
if (id) {
|
|
226
|
+
inputs[id] = {
|
|
227
|
+
value: child.attributes.value || '',
|
|
228
|
+
when: child.attributes.when,
|
|
229
|
+
unless: child.attributes.unless,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (child instanceof markdoc.Tag) {
|
|
236
|
+
collectInputsFromChildren(child.children, inputs);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return inputs;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function validateCodeWalkthroughCondition(
|
|
244
|
+
conditions: CodeWalkthroughConditions,
|
|
245
|
+
filters: Record<string, CodeWalkthroughFilter>,
|
|
246
|
+
allToggles: string[],
|
|
247
|
+
) {
|
|
248
|
+
const errors: string[] = [];
|
|
249
|
+
|
|
250
|
+
for (const [filterId, filterValue] of Object.entries(conditions)) {
|
|
251
|
+
if (!filters[filterId] && !allToggles.includes(filterId)) {
|
|
252
|
+
errors.push('Unknown filter: ' + filterId);
|
|
253
|
+
} else if (filterValue) {
|
|
254
|
+
const invalidFilterItems = getInvalidFilterValues(
|
|
255
|
+
filterValue,
|
|
256
|
+
filters[filterId]?.items || [],
|
|
257
|
+
);
|
|
258
|
+
if (invalidFilterItems.length > 0) {
|
|
259
|
+
errors.push(
|
|
260
|
+
`Filter item(s) are not defined on the filter '${filterId}': ${invalidFilterItems.join(', ')}`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return errors;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getInvalidFilterValues(
|
|
269
|
+
filterConditionValue: string | boolean | string[],
|
|
270
|
+
definedValues: CodeWalkthroughFilterItem[],
|
|
271
|
+
) {
|
|
272
|
+
const togglesArray = Array.isArray(filterConditionValue)
|
|
273
|
+
? filterConditionValue
|
|
274
|
+
: [filterConditionValue];
|
|
275
|
+
const items = definedValues.map((item) => item.value);
|
|
276
|
+
|
|
277
|
+
return togglesArray.filter((toggle) => typeof toggle !== 'boolean' && !items.includes(toggle));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function validateStepFilters(
|
|
281
|
+
filters: Record<string, CodeWalkthroughFilter>,
|
|
282
|
+
obj: Record<string, string>,
|
|
283
|
+
) {
|
|
284
|
+
function isValidFilter(filterKey: string, filterValue: string | string[]) {
|
|
285
|
+
if (!Object.prototype.hasOwnProperty.call(filters, filterKey)) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const validItems = filters[filterKey].items.map((item) => item.value);
|
|
290
|
+
|
|
291
|
+
if (Array.isArray(filterValue)) {
|
|
292
|
+
return filterValue.every((value) => validItems.includes(value));
|
|
293
|
+
} else {
|
|
294
|
+
return validItems.includes(filterValue);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (obj.when) {
|
|
299
|
+
for (const [key, value] of Object.entries(obj.when)) {
|
|
300
|
+
if (!isValidFilter(key, value)) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (obj.unless) {
|
|
307
|
+
for (const [key, value] of Object.entries(obj.unless)) {
|
|
308
|
+
if (!isValidFilter(key, value)) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MarkdocSchemaWrapper } from '@redocly/theme/markdoc/tags/types';
|
|
2
|
+
|
|
3
|
+
export const input: MarkdocSchemaWrapper = {
|
|
4
|
+
tagName: 'input',
|
|
5
|
+
schema: {
|
|
6
|
+
attributes: {
|
|
7
|
+
id: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
label: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
|
+
placeholder: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: false,
|
|
18
|
+
},
|
|
19
|
+
value: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: false,
|
|
22
|
+
},
|
|
23
|
+
unless: {
|
|
24
|
+
type: Object,
|
|
25
|
+
required: false,
|
|
26
|
+
},
|
|
27
|
+
when: {
|
|
28
|
+
type: Object,
|
|
29
|
+
required: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
selfClosing: true,
|
|
33
|
+
render: 'Input',
|
|
34
|
+
},
|
|
35
|
+
};
|
package/src/plugin.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports = function plugin() {
|
|
2
2
|
return { id: 'default-theme' };
|
|
3
|
-
}
|
|
3
|
+
};
|