@redocly/theme 0.9.12 → 0.9.14

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.
Files changed (38) hide show
  1. package/lib/Markdown/MarkdownWrapper.js +7 -7
  2. package/lib/Sidebar/FooterWrapper.d.ts +2 -2
  3. package/lib/Sidebar/FooterWrapper.js +6 -3
  4. package/lib/Sidebar/SidebarLayout.d.ts +6 -3
  5. package/lib/Sidebar/SidebarLayout.js +55 -7
  6. package/lib/Sidebar/index.d.ts +1 -0
  7. package/lib/Sidebar/index.js +1 -0
  8. package/lib/SidebarActions/ChangeViewButton.d.ts +8 -0
  9. package/lib/SidebarActions/ChangeViewButton.js +14 -0
  10. package/lib/SidebarActions/CollapseSidebarButton.d.ts +7 -0
  11. package/lib/SidebarActions/CollapseSidebarButton.js +13 -0
  12. package/lib/SidebarActions/SidebarActions.d.ts +20 -0
  13. package/lib/SidebarActions/SidebarActions.js +26 -0
  14. package/lib/SidebarActions/ToggleRightPanelButton.d.ts +7 -0
  15. package/lib/SidebarActions/ToggleRightPanelButton.js +13 -0
  16. package/lib/SidebarActions/index.d.ts +1 -0
  17. package/lib/SidebarActions/index.js +7 -0
  18. package/lib/SidebarActions/styled.d.ts +17 -0
  19. package/lib/SidebarActions/styled.js +124 -0
  20. package/lib/config.d.ts +774 -1814
  21. package/lib/config.js +271 -213
  22. package/lib/globalStyle.js +1 -2
  23. package/lib/index.d.ts +1 -0
  24. package/lib/index.js +1 -0
  25. package/package.json +6 -7
  26. package/src/Markdown/MarkdownWrapper.tsx +1 -1
  27. package/src/Sidebar/FooterWrapper.tsx +7 -4
  28. package/src/Sidebar/SidebarLayout.tsx +66 -18
  29. package/src/Sidebar/index.ts +1 -0
  30. package/src/SidebarActions/ChangeViewButton.tsx +20 -0
  31. package/src/SidebarActions/CollapseSidebarButton.tsx +21 -0
  32. package/src/SidebarActions/SidebarActions.tsx +64 -0
  33. package/src/SidebarActions/ToggleRightPanelButton.tsx +21 -0
  34. package/src/SidebarActions/index.tsx +1 -0
  35. package/src/SidebarActions/styled.tsx +157 -0
  36. package/src/config.ts +334 -222
  37. package/src/globalStyle.ts +1 -2
  38. package/src/index.ts +1 -0
package/src/config.ts CHANGED
@@ -1,234 +1,346 @@
1
- import { z } from 'zod';
1
+ import type { FromSchema } from 'json-schema-to-ts';
2
+ import type { MenuStyle } from './types/portal';
2
3
 
3
- const LogoConfig = z
4
- .object({
5
- image: z.string().optional(),
6
- altText: z.string().optional(),
7
- link: z.string().optional(),
8
- favicon: z.string().optional(),
9
- })
10
- .strict();
4
+ const logoConfigSchema = {
5
+ type: 'object',
6
+ properties: {
7
+ image: { type: 'string' },
8
+ altText: { type: 'string' },
9
+ link: { type: 'string' },
10
+ favicon: { type: 'string' },
11
+ },
12
+ additionalProperties: false,
13
+ } as const;
11
14
 
12
- const HideConfig = z.object({
13
- hide: z.boolean().optional(),
14
- });
15
+ const hideConfigSchema = {
16
+ type: 'object',
17
+ properties: {
18
+ hide: { type: 'boolean' },
19
+ },
20
+ additionalProperties: false,
21
+ } as const;
15
22
 
16
- const ScriptConfig = z
17
- .object({
18
- src: z.string(),
19
- async: z.boolean().optional(),
20
- crossorigin: z.string().optional(),
21
- defer: z.boolean().optional(),
22
- fetchpriority: z.string().optional(),
23
- integrity: z.string().optional(),
24
- module: z.boolean().optional(),
25
- nomodule: z.boolean().optional(),
26
- nonce: z.string().optional(),
27
- referrerpolicy: z.string().optional(),
28
- type: z.string().optional(),
29
- })
30
- .passthrough();
23
+ const scriptConfigSchema = {
24
+ type: 'object',
25
+ properties: {
26
+ src: { type: 'string' },
27
+ async: { type: 'boolean' },
28
+ crossorigin: { type: 'string' },
29
+ defer: { type: 'boolean' },
30
+ fetchpriority: { type: 'string' },
31
+ integrity: { type: 'string' },
32
+ module: { type: 'boolean' },
33
+ nomodule: { type: 'boolean' },
34
+ nonce: { type: 'string' },
35
+ referrerpolicy: { type: 'string' },
36
+ type: { type: 'string' },
37
+ },
38
+ required: ['src'],
39
+ additionalProperties: true,
40
+ } as const;
31
41
 
32
- const LinksConfig = z
33
- .object({
34
- href: z.string(),
42
+ const linksConfigSchema = {
43
+ type: 'object',
44
+ properties: {
45
+ href: { type: 'string' },
46
+ as: { type: 'string' },
47
+ crossorigin: { type: 'string' },
48
+ fetchpriority: { type: 'string' },
49
+ hreflang: { type: 'string' },
50
+ imagesizes: { type: 'string' },
51
+ imagesrcset: { type: 'string' },
52
+ integrity: { type: 'string' },
53
+ media: { type: 'string' },
54
+ prefetch: { type: 'string' },
55
+ referrerpolicy: { type: 'string' },
56
+ rel: { type: 'string' },
57
+ sizes: { type: 'string' },
58
+ title: { type: 'string' },
59
+ type: { type: 'string' },
60
+ },
61
+ required: ['href'],
62
+ additionalProperties: true,
63
+ } as const;
35
64
 
36
- as: z.string().optional(),
37
- crossorigin: z.string().optional(),
38
- fetchpriority: z.string().optional(),
39
- hreflang: z.string().optional(),
40
- imagesizes: z.string().optional(),
41
- imagesrcset: z.string().optional(),
42
- integrity: z.string().optional(),
43
- media: z.string().optional(),
44
- prefetch: z.string().optional(),
45
- referrerpolicy: z.string().optional(),
46
- rel: z.string().optional(),
47
- sizes: z.string().optional(),
48
- title: z.string().optional(),
49
- type: z.string().optional(),
50
- })
51
- .passthrough();
65
+ const markdownConfigSchema = {
66
+ type: 'object',
67
+ properties: {
68
+ frontMatterKeysToResolve: {
69
+ type: 'array',
70
+ items: { type: 'string' },
71
+ default: ['image', 'links'],
72
+ },
73
+ lastUpdatedBlock: {
74
+ type: 'object',
75
+ properties: {
76
+ format: {
77
+ type: 'string',
78
+ enum: ['timeago', 'iso', 'long', 'short'],
79
+ default: 'timeago',
80
+ },
81
+ locale: { type: 'string', default: 'en-US' },
82
+ ...hideConfigSchema.properties,
83
+ },
84
+ additionalProperties: false,
85
+ default: {},
86
+ },
87
+ toc: {
88
+ type: 'object',
89
+ properties: {
90
+ header: { type: 'string', default: 'On this page' },
91
+ depth: { type: 'number', default: 3 },
92
+ ...hideConfigSchema.properties,
93
+ },
94
+ additionalProperties: false,
95
+ default: {},
96
+ },
97
+ editPage: {
98
+ type: 'object',
99
+ properties: {
100
+ baseUrl: { type: 'string' },
101
+ icon: { type: 'string' },
102
+ text: { type: 'string', default: 'Edit this page' },
103
+ ...hideConfigSchema.properties,
104
+ },
105
+ additionalProperties: false,
106
+ default: {},
107
+ },
108
+ },
109
+ additionalProperties: false,
110
+ default: {},
111
+ } as const;
52
112
 
53
- const MarkdownConfig = z
54
- .object({
55
- frontMatterKeysToResolve: z.array(z.string()).default(['image', 'links']).optional(),
56
- lastUpdatedBlock: z
57
- .object({
58
- format: z.enum(['timeago', 'iso', 'long', 'short']).default('timeago').optional(),
59
- locale: z.string().default('en-US').optional(),
60
- })
61
- .extend(HideConfig.shape)
62
- .default({})
63
- .optional(),
64
- toc: z
65
- .object({
66
- header: z.string().default('On this page').optional(),
67
- depth: z.number().default(3).optional(),
68
- })
69
- .extend(HideConfig.shape)
70
- .optional()
71
- .default({}),
72
- editPage: z
73
- .object({
74
- baseUrl: z.string().optional(),
75
- icon: z.string().optional(),
76
- text: z.string().optional().default('Edit this page'),
77
- })
78
- .extend(HideConfig.shape)
79
- .default({})
80
- .optional(),
81
- })
82
- .strict()
83
- .default({});
113
+ const navItemSchema = {
114
+ type: 'object',
115
+ properties: {
116
+ page: { type: 'string' },
117
+ directory: { type: 'string' },
118
+ group: { type: 'string' },
119
+ label: { type: 'string' },
120
+ separator: { type: 'string' },
121
+ separatorLine: { type: 'boolean' },
122
+ version: { type: 'string' },
123
+ menuStyle: { type: 'string', enum: ['drilldown' as MenuStyle] },
124
+ expanded: { type: 'string', const: 'always' },
125
+ selectFirstItemOnExpand: { type: 'boolean' },
126
+ flatten: { type: 'boolean' },
127
+ },
128
+ } as const;
84
129
 
85
- export const ThemeConfig = z
86
- .object({
87
- imports: z.array(z.string()).default([]).optional(),
130
+ const navItemsSchema = {
131
+ type: 'array',
132
+ items: {
133
+ ...navItemSchema,
134
+ properties: {
135
+ ...navItemSchema.properties,
136
+ items: { type: 'array', items: navItemSchema },
137
+ },
138
+ },
139
+ } as const;
88
140
 
89
- logo: LogoConfig.optional(),
90
- navbar: z
91
- .object({
92
- items: z.array(z.any()).optional(), // todo: think about validation here
93
- })
94
- .extend(HideConfig.shape)
95
- .strict()
96
- .optional(),
141
+ export const themeConfigSchema = {
142
+ type: 'object',
143
+ properties: {
144
+ imports: {
145
+ type: 'array',
146
+ items: { type: 'string' },
147
+ default: [],
148
+ },
149
+ logo: logoConfigSchema,
150
+ navbar: {
151
+ type: 'object',
152
+ properties: {
153
+ items: navItemsSchema,
154
+ ...hideConfigSchema.properties,
155
+ },
156
+ additionalProperties: false,
157
+ },
158
+ footer: {
159
+ type: 'object',
160
+ properties: {
161
+ items: navItemsSchema,
162
+ copyrightText: { type: 'string' },
163
+ ...hideConfigSchema.properties,
164
+ },
165
+ additionalProperties: false,
166
+ },
167
+ sidebar: hideConfigSchema,
168
+ scripts: {
169
+ type: 'object',
170
+ properties: {
171
+ head: { type: 'array', items: scriptConfigSchema },
172
+ body: { type: 'array', items: scriptConfigSchema },
173
+ },
174
+ additionalProperties: false,
175
+ },
176
+ links: { type: 'array', items: linksConfigSchema },
177
+ feedback: {
178
+ type: 'object',
179
+ properties: {
180
+ type: {
181
+ type: 'string',
182
+ enum: ['rating', 'sentiment', 'comment', 'reasons'],
183
+ default: 'sentiment',
184
+ },
185
+ settings: {
186
+ type: 'object',
187
+ properties: {
188
+ label: { type: 'string' },
189
+ submitText: { type: 'string' },
190
+ max: { type: 'number' },
191
+ buttonText: { type: 'string' },
192
+ multi: { type: 'boolean' },
193
+ items: { type: 'array', items: { type: 'string' }, minItems: 1 },
194
+ reasons: {
195
+ type: 'object',
196
+ properties: {
197
+ enable: { type: 'boolean', default: true },
198
+ multi: { type: 'boolean' },
199
+ label: { type: 'string' },
200
+ items: { type: 'array', items: { type: 'string' } },
201
+ },
202
+ additionalProperties: false,
203
+ },
204
+ comment: {
205
+ type: 'object',
206
+ properties: {
207
+ enable: { type: 'boolean', default: true },
208
+ label: { type: 'string' },
209
+ likeLabel: { type: 'string' },
210
+ dislikeLabel: { type: 'string' },
211
+ },
212
+ additionalProperties: false,
213
+ },
214
+ },
215
+ additionalProperties: false,
216
+ ...hideConfigSchema.properties,
217
+ },
218
+ },
219
+ additionalProperties: false,
220
+ default: {},
221
+ },
222
+ search: {
223
+ type: 'object',
224
+ properties: {
225
+ placement: {
226
+ type: 'string',
227
+ default: 'navbar',
228
+ },
229
+ shortcuts: {
230
+ type: 'array',
231
+ items: { type: 'string' },
232
+ default: ['/'],
233
+ },
234
+ ...hideConfigSchema.properties,
235
+ },
236
+ additionalProperties: false,
237
+ default: {},
238
+ },
239
+ colorMode: {
240
+ type: 'object',
241
+ properties: {
242
+ ignoreDetection: { type: 'boolean' },
243
+ modes: {
244
+ type: 'array',
245
+ items: { type: 'string' },
246
+ default: ['light', 'dark'],
247
+ },
248
+ ...hideConfigSchema.properties,
249
+ },
250
+ additionalProperties: false,
251
+ default: {},
252
+ },
253
+ navigation: {
254
+ type: 'object',
255
+ properties: {
256
+ nextButton: {
257
+ type: 'object',
258
+ properties: {
259
+ text: { type: 'string', default: 'Next to {label}' },
260
+ ...hideConfigSchema.properties,
261
+ },
262
+ additionalProperties: false,
263
+ default: {},
264
+ },
265
+ previousButton: {
266
+ type: 'object',
267
+ properties: {
268
+ text: { type: 'string', default: 'Back to {label}' },
269
+ ...hideConfigSchema.properties,
270
+ },
271
+ additionalProperties: false,
272
+ default: {},
273
+ },
274
+ },
275
+ additionalProperties: false,
276
+ default: {},
277
+ },
278
+ codeSnippet: {
279
+ type: 'object',
280
+ properties: {
281
+ copy: {
282
+ type: 'object',
283
+ properties: {
284
+ buttonText: { type: 'string', default: 'Copy' },
285
+ tooltipText: { type: 'string', default: 'Copy to clipboard' },
286
+ toasterText: { type: 'string', default: 'Copied!' },
287
+ toasterDuration: { type: 'number', default: 1500 },
288
+ ...hideConfigSchema.properties,
289
+ },
290
+ additionalProperties: false,
291
+ default: {},
292
+ },
293
+ report: {
294
+ type: 'object',
295
+ properties: {
296
+ tooltipText: { type: 'string', default: 'Report a problem' },
297
+ label: { type: 'string' },
298
+ ...hideConfigSchema.properties,
299
+ },
300
+ additionalProperties: false,
301
+ default: { hide: true },
302
+ },
303
+ },
304
+ additionalProperties: false,
305
+ default: {},
306
+ },
307
+ markdown: markdownConfigSchema,
308
+ openapi: { type: 'object', additionalProperties: true },
309
+ graphql: { type: 'object', additionalProperties: true },
310
+ analytics: {
311
+ type: ['array', 'boolean', 'number', 'object', 'string'],
312
+ },
313
+ userProfile: {
314
+ type: 'object',
315
+ properties: {
316
+ loginLabel: { type: 'string', default: 'Login' },
317
+ logoutLabel: { type: 'string', default: 'Logout' },
318
+ menu: {
319
+ type: 'array',
320
+ items: {
321
+ type: 'object',
322
+ properties: {
323
+ label: { type: 'string' },
324
+ external: { type: 'boolean' },
325
+ link: { type: 'string' },
326
+ separatorLine: { type: 'boolean' },
327
+ },
328
+ additionalProperties: true,
329
+ },
330
+ default: [],
331
+ },
332
+ ...hideConfigSchema.properties,
333
+ },
334
+ additionalProperties: false,
335
+ default: {},
336
+ },
337
+ },
338
+ additionalProperties: true,
339
+ default: {},
340
+ } as const;
97
341
 
98
- footer: z
99
- .object({
100
- items: z.array(z.any()).optional(), // todo: think about validation here
101
- copyrightText: z.string().optional(),
102
- })
103
- .extend(HideConfig.shape)
104
- .strict()
105
- .optional(),
106
- sidebar: HideConfig.strict().optional(),
107
-
108
- scripts: z
109
- .object({
110
- head: z.array(ScriptConfig).optional(),
111
- body: z.array(ScriptConfig).optional(),
112
- })
113
- .optional(),
114
- links: z.array(LinksConfig).optional(),
115
-
116
- feedback: z
117
- .object({
118
- type: z.enum(['rating', 'sentiment', 'comment', 'reasons']).default('sentiment'),
119
- settings: z
120
- .object({
121
- label: z.string().optional(),
122
- submitText: z.string().optional(),
123
- max: z.number().optional(),
124
- buttonText: z.string().optional(),
125
- multi: z.boolean().optional(),
126
- items: z.array(z.string()).min(1).optional(),
127
- reasons: z
128
- .object({
129
- enable: z.boolean().default(true),
130
- multi: z.boolean().optional(),
131
- label: z.string().optional(),
132
- items: z.array(z.string()),
133
- })
134
- .optional(),
135
- comment: z
136
- .object({
137
- enable: z.boolean().default(true),
138
- label: z.string().optional(),
139
- likeLabel: z.string().optional(),
140
- dislikeLabel: z.string().optional(),
141
- })
142
- .optional(),
143
- })
144
- .optional(),
145
- })
146
- .extend(HideConfig.shape)
147
- .strict()
148
- .default({})
149
- .optional(),
150
-
151
- search: z
152
- .object({
153
- placement: z.string().default('navbar').optional(),
154
- shortcuts: z.array(z.string()).default(['/']).optional(),
155
- })
156
- .extend(HideConfig.shape)
157
- .strict()
158
- .default({})
159
- .optional(),
160
-
161
- colorMode: z
162
- .object({
163
- ignoreDetection: z.boolean().optional(),
164
- modes: z.array(z.string()).default(['light', 'dark']).optional(),
165
- })
166
- .extend(HideConfig.shape)
167
- .strict()
168
- .optional()
169
- .default({}),
170
- navigation: z
171
- .object({
172
- nextButton: z
173
- .object({ text: z.string().default('Next to {label}') })
174
- .extend(HideConfig.shape)
175
- .optional()
176
- .default({}),
177
- previousButton: z
178
- .object({ text: z.string().default('Back to {label}') })
179
- .extend(HideConfig.shape)
180
- .optional()
181
- .default({}),
182
- })
183
- .strict()
184
- .optional()
185
- .default({}),
186
- codeSnippet: z
187
- .object({
188
- copy: z
189
- .object({
190
- buttonText: z.string().default('Copy').optional(),
191
- tooltipText: z.string().default('Copy to clipboard').optional(),
192
- toasterText: z.string().default('Copied!').optional(),
193
- toasterDuration: z.number().default(1500).optional(),
194
- })
195
- .extend(HideConfig.shape)
196
- .optional()
197
- .default({}),
198
- report: z
199
- .object({
200
- tooltipText: z.string().default('Report a problem').optional(),
201
- label: z.string().optional(),
202
- })
203
- .extend(HideConfig.shape)
204
- .optional()
205
- .default({ hide: true }),
206
- })
207
- .strict()
208
- .default({})
209
- .optional(),
210
- markdown: MarkdownConfig.optional(),
211
- openapi: z.object({}).passthrough().optional(),
212
- graphql: z.object({}).passthrough().optional(),
213
- analytics: z.any().optional(),
214
- userProfile: z
215
- .object({
216
- loginLabel: z.string().default('Login').optional(),
217
- logoutLabel: z.string().default('Logout').optional(),
218
- menu: z.array(z.any()).optional(), // should be same as navbar items type
219
- })
220
- .extend(HideConfig.shape)
221
- .optional()
222
- .default({}),
223
- })
224
- .passthrough()
225
- .default({});
226
-
227
- export type ThemeConfig = z.infer<typeof ThemeConfig>;
228
- // export type ThemeUIConfig = Omit<ThemeConfig, 'navbar' | 'footer' | 'links' | 'scripts'> & {
342
+ export type ThemeConfig = FromSchema<typeof themeConfigSchema>;
229
343
  export type ThemeUIConfig = ThemeConfig & {
230
- navbar?: any; // TODO
231
- footer?: any; // TODO
232
344
  auth?: {
233
345
  // used by portal dev login emulator
234
346
  idpsInfo?: {
@@ -243,4 +355,4 @@ export type ThemeUIConfig = ThemeConfig & {
243
355
  };
244
356
  };
245
357
 
246
- export type MarkdownConfig = z.infer<typeof MarkdownConfig>;
358
+ export type MarkdownConfig = FromSchema<typeof markdownConfigSchema>;
@@ -1285,8 +1285,7 @@ const apiReferenceDocs = css`
1285
1285
  /**
1286
1286
  * @tokens API Reference Schemas Layout
1287
1287
  */
1288
-
1289
- --layout-controls-top-offset: 20px; // @presenter Spacing
1288
+ --layout-controls-margin: 20px; // @presenter Spacing
1290
1289
  --layout-controls-height: 36px; // @presenter Spacing
1291
1290
  --layout-controls-width: 36px; // @presenter Spacing
1292
1291
 
package/src/index.ts CHANGED
@@ -24,3 +24,4 @@ export * from './config';
24
24
  export * from './Pages';
25
25
  export * from './Markdown';
26
26
  export * from './ReferenceDocs';
27
+ export * from './SidebarActions';