@docusaurus/theme-classic 2.0.0-beta.15 → 2.0.0-beta.16

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 (143) hide show
  1. package/lib/getSwizzleConfig.js +102 -0
  2. package/lib/index.js +14 -11
  3. package/lib/theme-classic.d.ts +123 -97
  4. package/lib/translations.js +29 -32
  5. package/lib/validateThemeConfig.js +7 -4
  6. package/lib-next/theme/AnnouncementBar/index.js +1 -4
  7. package/lib-next/theme/BackToTopButton/index.js +6 -6
  8. package/lib-next/theme/BackToTopButton/styles.module.css +3 -1
  9. package/lib-next/theme/BlogLayout/index.js +1 -4
  10. package/lib-next/theme/BlogListPage/index.js +1 -4
  11. package/lib-next/theme/BlogListPaginator/index.js +1 -4
  12. package/lib-next/theme/BlogPostAuthor/index.js +18 -24
  13. package/lib-next/theme/BlogPostItem/index.js +12 -4
  14. package/lib-next/theme/BlogPostPage/index.js +4 -6
  15. package/lib-next/theme/BlogPostPaginator/index.js +1 -4
  16. package/lib-next/theme/BlogTagsListPage/index.js +1 -4
  17. package/lib-next/theme/BlogTagsPostsPage/index.js +4 -2
  18. package/lib-next/theme/CodeBlock/index.js +2 -1
  19. package/lib-next/theme/Details/index.js +2 -1
  20. package/lib-next/theme/DocBreadcrumbs/index.js +76 -0
  21. package/lib-next/theme/DocBreadcrumbs/styles.module.css +26 -0
  22. package/lib-next/theme/DocCard/index.js +12 -1
  23. package/lib-next/theme/DocCard/styles.module.css +1 -1
  24. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +2 -0
  25. package/lib-next/theme/DocItem/index.js +8 -5
  26. package/lib-next/theme/DocPage/index.js +2 -4
  27. package/lib-next/theme/DocPage/styles.module.css +3 -3
  28. package/lib-next/theme/DocPaginator/index.js +1 -4
  29. package/lib-next/theme/DocSidebar/styles.module.css +4 -4
  30. package/lib-next/theme/DocSidebarItem/index.js +39 -14
  31. package/lib-next/theme/DocSidebarItem/styles.module.css +3 -10
  32. package/lib-next/theme/DocTagsListPage/index.js +1 -4
  33. package/lib-next/theme/DocVersionBadge/index.js +8 -1
  34. package/lib-next/theme/Footer/index.js +8 -4
  35. package/lib-next/theme/Heading/index.js +0 -1
  36. package/lib-next/theme/Heading/styles.module.css +16 -0
  37. package/lib-next/theme/IconArrow/index.js +1 -4
  38. package/lib-next/theme/IconEdit/index.js +1 -4
  39. package/lib-next/theme/IconExternalLink/index.js +1 -4
  40. package/lib-next/theme/IconLanguage/index.js +1 -4
  41. package/lib-next/theme/IconMenu/index.js +6 -4
  42. package/lib-next/theme/Layout/index.js +1 -4
  43. package/lib-next/theme/LayoutHead/index.js +4 -0
  44. package/lib-next/theme/Logo/index.js +1 -4
  45. package/lib-next/theme/MDXComponents/index.js +4 -3
  46. package/lib-next/theme/MDXPage/index.js +1 -4
  47. package/lib-next/theme/Navbar/index.js +1 -3
  48. package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +1 -3
  49. package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +2 -2
  50. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +1 -3
  51. package/lib-next/theme/NavbarItem/LocaleDropdownNavbarItem/index.js +8 -1
  52. package/lib-next/theme/NavbarItem/index.js +2 -2
  53. package/lib-next/theme/NotFound.js +1 -4
  54. package/lib-next/theme/PaginatorNavLink/index.js +1 -4
  55. package/lib-next/theme/SearchBar.js +1 -1
  56. package/lib-next/theme/SearchMetadata/index.js +11 -6
  57. package/lib-next/theme/SkipToContent/index.js +1 -3
  58. package/lib-next/theme/TOC/index.js +2 -5
  59. package/lib-next/theme/TOCInline/index.js +1 -4
  60. package/lib-next/theme/TOCItems/index.js +3 -3
  61. package/lib-next/theme/TabItem/index.js +1 -4
  62. package/lib-next/theme/Tabs/__tests__/index.test.js +3 -1
  63. package/lib-next/theme/Tabs/index.js +1 -1
  64. package/lib-next/theme/Tag/index.js +1 -4
  65. package/lib-next/theme/TagsListByLetter/index.js +1 -3
  66. package/lib-next/theme/ThemedImage/index.js +1 -4
  67. package/lib-next/theme/ThemedImage/styles.module.css +2 -2
  68. package/lib-next/theme/Toggle/index.js +25 -2
  69. package/lib-next/theme/prism-include-languages.js +17 -23
  70. package/package.json +21 -22
  71. package/src/getSwizzleConfig.ts +101 -0
  72. package/src/index.ts +7 -21
  73. package/src/theme/AnnouncementBar/index.tsx +1 -3
  74. package/src/theme/BackToTopButton/index.tsx +8 -7
  75. package/src/theme/BackToTopButton/styles.module.css +3 -1
  76. package/src/theme/BlogLayout/index.tsx +1 -3
  77. package/src/theme/BlogListPage/index.tsx +1 -3
  78. package/src/theme/BlogListPaginator/index.tsx +1 -3
  79. package/src/theme/BlogPostAuthor/index.tsx +18 -23
  80. package/src/theme/BlogPostItem/index.tsx +10 -4
  81. package/src/theme/BlogPostPage/index.tsx +4 -5
  82. package/src/theme/BlogPostPaginator/index.tsx +1 -3
  83. package/src/theme/BlogTagsListPage/index.tsx +1 -3
  84. package/src/theme/BlogTagsPostsPage/index.tsx +3 -1
  85. package/src/theme/CodeBlock/index.tsx +2 -1
  86. package/src/theme/Details/index.tsx +2 -1
  87. package/src/theme/DocBreadcrumbs/index.tsx +91 -0
  88. package/src/theme/DocBreadcrumbs/styles.module.css +26 -0
  89. package/src/theme/DocCard/index.tsx +10 -1
  90. package/src/theme/DocCard/styles.module.css +1 -1
  91. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +2 -0
  92. package/src/theme/DocItem/index.tsx +7 -4
  93. package/src/theme/DocPage/index.tsx +2 -4
  94. package/src/theme/DocPage/styles.module.css +3 -3
  95. package/src/theme/DocPaginator/index.tsx +1 -3
  96. package/src/theme/DocSidebar/styles.module.css +4 -4
  97. package/src/theme/DocSidebarItem/index.tsx +43 -13
  98. package/src/theme/DocSidebarItem/styles.module.css +3 -10
  99. package/src/theme/DocTagsListPage/index.tsx +1 -3
  100. package/src/theme/DocVersionBadge/index.tsx +6 -1
  101. package/src/theme/Footer/index.tsx +8 -4
  102. package/src/theme/Heading/index.tsx +0 -1
  103. package/src/theme/Heading/styles.module.css +16 -0
  104. package/src/theme/IconArrow/index.tsx +1 -3
  105. package/src/theme/IconEdit/index.tsx +4 -3
  106. package/src/theme/IconExternalLink/index.tsx +4 -3
  107. package/src/theme/IconLanguage/index.tsx +5 -3
  108. package/src/theme/IconMenu/index.tsx +1 -3
  109. package/src/theme/Layout/index.tsx +1 -3
  110. package/src/theme/LayoutHead/index.tsx +4 -0
  111. package/src/theme/Logo/index.tsx +1 -3
  112. package/src/theme/MDXComponents/index.tsx +4 -3
  113. package/src/theme/MDXPage/index.tsx +1 -3
  114. package/src/theme/Navbar/index.tsx +1 -3
  115. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +1 -3
  116. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +2 -2
  117. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +4 -3
  118. package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +8 -1
  119. package/src/theme/NavbarItem/index.tsx +2 -2
  120. package/src/theme/NotFound.tsx +1 -3
  121. package/src/theme/PaginatorNavLink/index.tsx +1 -3
  122. package/src/theme/SearchBar.tsx +2 -1
  123. package/src/theme/SearchMetadata/index.tsx +12 -6
  124. package/src/theme/SkipToContent/index.tsx +1 -3
  125. package/src/theme/TOC/index.tsx +3 -5
  126. package/src/theme/TOCCollapsible/index.tsx +2 -2
  127. package/src/theme/TOCInline/index.tsx +3 -5
  128. package/src/theme/TOCItems/index.tsx +11 -7
  129. package/src/theme/TabItem/index.tsx +5 -3
  130. package/src/theme/Tabs/index.tsx +1 -1
  131. package/src/theme/Tag/index.tsx +1 -3
  132. package/src/theme/TagsListByLetter/index.tsx +1 -3
  133. package/src/theme/ThemedImage/index.tsx +1 -3
  134. package/src/theme/ThemedImage/styles.module.css +2 -2
  135. package/src/theme/Toggle/index.tsx +26 -2
  136. package/src/theme/prism-include-languages.ts +20 -23
  137. package/src/theme-classic.d.ts +123 -97
  138. package/src/translations.ts +41 -39
  139. package/src/validateThemeConfig.ts +10 -8
  140. package/lib-next/theme/DocSidebarItems/styles.module.css +0 -20
  141. package/lib-next/theme/Heading/styles.css +0 -22
  142. package/src/theme/DocSidebarItems/styles.module.css +0 -20
  143. package/src/theme/Heading/styles.css +0 -22
@@ -15,7 +15,7 @@ import type {
15
15
  SimpleFooter,
16
16
  } from '@docusaurus/theme-common';
17
17
 
18
- import {keyBy, chain} from 'lodash';
18
+ import _ from 'lodash';
19
19
  import {mergeTranslations} from '@docusaurus/utils';
20
20
 
21
21
  function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
@@ -30,15 +30,17 @@ function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
30
30
 
31
31
  const allNavbarItems = flattenNavbarItems(navbar.items);
32
32
 
33
- const navbarItemsTranslations: TranslationFileContent = chain(
34
- allNavbarItems.filter((navbarItem) => !!navbarItem.label),
35
- )
36
- .keyBy((navbarItem) => `item.label.${navbarItem.label}`)
37
- .mapValues((navbarItem) => ({
38
- message: navbarItem.label!,
39
- description: `Navbar item with label ${navbarItem.label}`,
40
- }))
41
- .value();
33
+ const navbarItemsTranslations: TranslationFileContent = Object.fromEntries(
34
+ allNavbarItems
35
+ .filter((navbarItem) => navbarItem.label)
36
+ .map((navbarItem) => [
37
+ `item.label.${navbarItem.label}`,
38
+ {
39
+ message: navbarItem.label!,
40
+ description: `Navbar item with label ${navbarItem.label}`,
41
+ },
42
+ ]),
43
+ );
42
44
 
43
45
  const titleTranslations: TranslationFileContent = navbar.title
44
46
  ? {title: {message: navbar.title, description: 'The title in the navbar'}}
@@ -78,33 +80,33 @@ function isMultiColumnFooterLinks(
78
80
  }
79
81
 
80
82
  function getFooterTranslationFile(footer: Footer): TranslationFileContent {
81
- const footerLinkTitles: TranslationFileContent = chain(
82
- isMultiColumnFooterLinks(footer.links)
83
- ? footer.links.filter((link) => !!link.title)
84
- : [],
85
- )
86
- .keyBy((link) => `link.title.${link.title}`)
87
- .mapValues((link) => ({
88
- message: link.title!,
89
- description: `The title of the footer links column with title=${link.title} in the footer`,
90
- }))
91
- .value();
92
-
93
- const footerLinkLabels: TranslationFileContent = chain(
94
- isMultiColumnFooterLinks(footer.links)
95
- ? footer.links
96
- .flatMap((link) => link.items)
97
- .filter((link) => !!link.label)
98
- : footer.links.filter((link) => !!link.label),
99
- )
100
- .keyBy((linkItem) => `link.item.label.${linkItem.label}`)
101
- .mapValues((linkItem) => ({
102
- message: linkItem.label!,
103
- description: `The label of footer link with label=${
104
- linkItem.label
105
- } linking to ${linkItem.to ?? linkItem.href}`,
106
- }))
107
- .value();
83
+ const footerLinkTitles: TranslationFileContent = Object.fromEntries(
84
+ (isMultiColumnFooterLinks(footer.links)
85
+ ? footer.links.filter((link) => link.title)
86
+ : []
87
+ ).map((link) => [
88
+ `link.title.${link.title}`,
89
+ {
90
+ message: link.title!,
91
+ description: `The title of the footer links column with title=${link.title} in the footer`,
92
+ },
93
+ ]),
94
+ );
95
+
96
+ const footerLinkLabels: TranslationFileContent = Object.fromEntries(
97
+ (isMultiColumnFooterLinks(footer.links)
98
+ ? footer.links.flatMap((link) => link.items).filter((link) => link.label)
99
+ : footer.links.filter((link) => link.label)
100
+ ).map((link) => [
101
+ `link.item.label.${link.label}`,
102
+ {
103
+ message: link.label!,
104
+ description: `The label of footer link with label=${
105
+ link.label
106
+ } linking to ${link.to ?? link.href}`,
107
+ },
108
+ ]),
109
+ );
108
110
 
109
111
  const copyright: TranslationFileContent = footer.copyright
110
112
  ? {
@@ -171,12 +173,12 @@ export function translateThemeConfig({
171
173
  themeConfig,
172
174
  translationFiles,
173
175
  }: {
174
- // Why partial? To make TS correctly figure out the contravariance in parameter.
176
+ // To make TS correctly figure out the contravariance in parameter.
175
177
  // In practice it's always normalized
176
178
  themeConfig: ThemeConfig;
177
179
  translationFiles: TranslationFile[];
178
180
  }): ThemeConfig {
179
- const translationFilesMap: Record<string, TranslationFile> = keyBy(
181
+ const translationFilesMap: Record<string, TranslationFile> = _.keyBy(
180
182
  translationFiles,
181
183
  (f) => f.path,
182
184
  );
@@ -29,7 +29,7 @@ const DEFAULT_COLOR_MODE_CONFIG = {
29
29
  },
30
30
  };
31
31
 
32
- const DEFAULT_CONFIG = {
32
+ export const DEFAULT_CONFIG = {
33
33
  colorMode: DEFAULT_COLOR_MODE_CONFIG,
34
34
  docs: DEFAULT_DOCS_CONFIG,
35
35
  metadata: [],
@@ -54,8 +54,8 @@ const NavbarItemBaseSchema = Joi.object({
54
54
  label: Joi.string(),
55
55
  className: Joi.string(),
56
56
  })
57
- // We allow any unknown attributes on the links
58
- // (users may need additional attributes like target, aria-role, data-customAttribute...)
57
+ // We allow any unknown attributes on the links (users may need additional
58
+ // attributes like target, aria-role, data-customAttribute...)
59
59
  .unknown();
60
60
 
61
61
  const DefaultNavbarItemSchema = NavbarItemBaseSchema.append({
@@ -116,6 +116,10 @@ const DropdownSubitemSchema = Joi.object({
116
116
  is: itemWithType('doc'),
117
117
  then: DocItemSchema,
118
118
  },
119
+ {
120
+ is: itemWithType('docSidebar'),
121
+ then: DocSidebarItemSchema,
122
+ },
119
123
  {
120
124
  is: itemWithType(undefined),
121
125
  then: DefaultNavbarItemSchema,
@@ -251,15 +255,15 @@ const FooterLinkItemSchema = Joi.object({
251
255
  .with('to', 'label')
252
256
  .with('href', 'label')
253
257
  .nand('html', 'label')
254
- // We allow any unknown attributes on the links
255
- // (users may need additional attributes like target, aria-role, data-customAttribute...)
258
+ // We allow any unknown attributes on the links (users may need additional
259
+ // attributes like target, aria-role, data-customAttribute...)
256
260
  .unknown();
257
261
 
258
262
  const CustomCssSchema = Joi.alternatives()
259
263
  .try(Joi.array().items(Joi.string().required()), Joi.string().required())
260
264
  .optional();
261
265
 
262
- const ThemeConfigSchema = Joi.object({
266
+ export const ThemeConfigSchema = Joi.object({
263
267
  // TODO temporary (@alpha-58)
264
268
  disableDarkMode: Joi.any().forbidden().messages({
265
269
  'any.unknown':
@@ -382,8 +386,6 @@ const ThemeConfigSchema = Joi.object({
382
386
  }).default(DEFAULT_CONFIG.tableOfContents),
383
387
  });
384
388
 
385
- export {DEFAULT_CONFIG, ThemeConfigSchema};
386
-
387
389
  export function validateThemeConfig({
388
390
  validate,
389
391
  themeConfig,
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- @media (min-width: 997px) {
9
- .menuLinkText {
10
- cursor: initial;
11
- }
12
-
13
- .menuLinkText:hover {
14
- background: none;
15
- }
16
-
17
- .menuLinkText.hasHref {
18
- cursor: pointer;
19
- }
20
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- .hash-link {
9
- opacity: 0;
10
- padding-left: 0.5rem;
11
- transition: opacity var(--ifm-transition-fast);
12
- user-select: none;
13
- }
14
-
15
- .hash-link::before {
16
- content: '#';
17
- }
18
-
19
- .hash-link:focus,
20
- *:hover > .hash-link {
21
- opacity: 1;
22
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- @media (min-width: 997px) {
9
- .menuLinkText {
10
- cursor: initial;
11
- }
12
-
13
- .menuLinkText:hover {
14
- background: none;
15
- }
16
-
17
- .menuLinkText.hasHref {
18
- cursor: pointer;
19
- }
20
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- .hash-link {
9
- opacity: 0;
10
- padding-left: 0.5rem;
11
- transition: opacity var(--ifm-transition-fast);
12
- user-select: none;
13
- }
14
-
15
- .hash-link::before {
16
- content: '#';
17
- }
18
-
19
- .hash-link:focus,
20
- *:hover > .hash-link {
21
- opacity: 1;
22
- }