@docusaurus/types 3.1.0 → 3.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/types",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Common types for Docusaurus packages.",
5
5
  "types": "./src/index.d.ts",
6
6
  "publishConfig": {
@@ -27,5 +27,5 @@
27
27
  "react": "^18.0.0",
28
28
  "react-dom": "^18.0.0"
29
29
  },
30
- "gitHead": "a5e675821f0e8b70b591fcebf19fd60a70d55548"
30
+ "gitHead": "5af143651b26b39761361acd96e9c5be7ba0cb25"
31
31
  }
package/src/context.d.ts CHANGED
@@ -31,6 +31,7 @@ export type GlobalData = {[pluginName: string]: {[pluginId: string]: unknown}};
31
31
 
32
32
  export type LoadContext = {
33
33
  siteDir: string;
34
+ siteVersion: string | undefined;
34
35
  generatedFilesDir: string;
35
36
  siteConfig: DocusaurusConfig;
36
37
  siteConfigPath: string;
package/src/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export {
45
45
 
46
46
  export {
47
47
  Plugin,
48
+ PluginIdentifier,
48
49
  InitializedPlugin,
49
50
  LoadedPlugin,
50
51
  PluginModule,
@@ -69,6 +70,7 @@ export {
69
70
 
70
71
  export {
71
72
  RouteConfig,
73
+ RouteMetadata,
72
74
  RouteContext,
73
75
  PluginRouteContext,
74
76
  Registry,
package/src/plugin.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {TranslationFile} from './i18n';
8
+ import type {CodeTranslations, TranslationFile} from './i18n';
9
9
  import type {RuleSetRule, Configuration as WebpackConfiguration} from 'webpack';
10
10
  import type {CustomizeRuleString} from 'webpack-merge/dist/types';
11
11
  import type {CommanderStatic} from 'commander';
@@ -18,11 +18,11 @@ import type {RouteConfig} from './routing';
18
18
 
19
19
  export type PluginOptions = {id?: string} & {[key: string]: unknown};
20
20
 
21
- export type PluginConfig =
21
+ export type PluginConfig<Content = unknown> =
22
22
  | string
23
23
  | [string, PluginOptions]
24
- | [PluginModule, PluginOptions]
25
- | PluginModule
24
+ | [PluginModule<Content>, PluginOptions]
25
+ | PluginModule<Content>
26
26
  | false
27
27
  | null;
28
28
 
@@ -110,7 +110,9 @@ export type Plugin<Content = unknown> = {
110
110
  contentLoaded?: (args: {
111
111
  /** The content loaded by this plugin instance */
112
112
  content: Content; //
113
- /** Content loaded by ALL the plugins */
113
+ actions: PluginContentLoadedActions;
114
+ }) => Promise<void> | void;
115
+ allContentLoaded?: (args: {
114
116
  allContent: AllContent;
115
117
  actions: PluginContentLoadedActions;
116
118
  }) => Promise<void> | void;
@@ -163,6 +165,15 @@ export type Plugin<Content = unknown> = {
163
165
  }) => ThemeConfig;
164
166
  };
165
167
 
168
+ /**
169
+ * Data required to uniquely identify a plugin
170
+ * The name or instance id alone is not enough
171
+ */
172
+ export type PluginIdentifier = {
173
+ readonly name: string;
174
+ readonly id: string;
175
+ };
176
+
166
177
  export type InitializedPlugin = Plugin & {
167
178
  readonly options: Required<PluginOptions>;
168
179
  readonly version: PluginVersionInformation;
@@ -172,10 +183,15 @@ export type InitializedPlugin = Plugin & {
172
183
 
173
184
  export type LoadedPlugin = InitializedPlugin & {
174
185
  readonly content: unknown;
186
+ readonly globalData: unknown;
187
+ readonly routes: RouteConfig[];
188
+ readonly defaultCodeTranslations: CodeTranslations;
175
189
  };
176
190
 
177
- export type PluginModule = {
178
- (context: LoadContext, options: unknown): Plugin | Promise<Plugin>;
191
+ export type PluginModule<Content = unknown> = {
192
+ (context: LoadContext, options: unknown):
193
+ | Plugin<Content>
194
+ | Promise<Plugin<Content>>;
179
195
  validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
180
196
  validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;
181
197
 
package/src/routing.d.ts CHANGED
@@ -11,7 +11,7 @@ import type {ParsedUrlQueryInput} from 'querystring';
11
11
  * A "module" represents a unit of serialized data emitted from the plugin. It
12
12
  * will be imported on client-side and passed as props, context, etc.
13
13
  *
14
- * If it's a string, it's a file path that Webpack can `require`; if it's
14
+ * If it's a string, it's a file path that the bundler can `require`; if it's
15
15
  * an object, it can also contain `query` or other metadata.
16
16
  */
17
17
  export type Module =
@@ -36,14 +36,45 @@ export type RouteModules = {
36
36
  [propName: string]: Module | RouteModules | RouteModules[];
37
37
  };
38
38
 
39
+ /**
40
+ * Plugin authors can assign extra metadata to the created routes
41
+ * It is only available on the Node.js side, and not sent to the browser
42
+ * Optional: plugin authors are encouraged but not required to provide it
43
+ *
44
+ * Some plugins might use this data to provide additional features.
45
+ * This is the case of the sitemap plugin to provide support for "lastmod".
46
+ * See also: https://github.com/facebook/docusaurus/pull/9954
47
+ */
48
+ export type RouteMetadata = {
49
+ /**
50
+ * The source code file path that led to the creation of the current route
51
+ * In official content plugins, this is usually a Markdown or React file
52
+ * This path is expected to be relative to the site directory
53
+ */
54
+ sourceFilePath?: string;
55
+ /**
56
+ * The last updated date of this route
57
+ * This is generally read from the Git history of the sourceFilePath
58
+ * but can also be provided through other means (usually front matter)
59
+ *
60
+ * This has notably been introduced for adding "lastmod" support to the
61
+ * sitemap plugin, see https://github.com/facebook/docusaurus/pull/9954
62
+ */
63
+ lastUpdatedAt?: number;
64
+ };
65
+
39
66
  /**
40
67
  * Represents a "slice" of the final route structure returned from the plugin
41
68
  * `addRoute` action.
42
69
  */
43
70
  export type RouteConfig = {
44
- /** With leading slash. Trailing slash will be normalized by config. */
71
+ /**
72
+ * With leading slash. Trailing slash will be normalized by config.
73
+ */
45
74
  path: string;
46
- /** Component used to render this route, a path that Webpack can `require`. */
75
+ /**
76
+ * Component used to render this route, a path that the bundler can `require`.
77
+ */
47
78
  component: string;
48
79
  /**
49
80
  * Props. Each entry should be `[propName]: pathToPropModule` (created with
@@ -56,13 +87,31 @@ export type RouteConfig = {
56
87
  * here will be namespaced under {@link RouteContext.data}.
57
88
  */
58
89
  context?: RouteModules;
59
- /** Nested routes config. */
90
+ /**
91
+ * Nested routes config, useful for "layout routes" having subroutes.
92
+ */
60
93
  routes?: RouteConfig[];
61
- /** React router config option: `exact` routes would not match subroutes. */
94
+ /**
95
+ * React router config option: `exact` routes would not match subroutes.
96
+ */
62
97
  exact?: boolean;
63
- /** Used to sort routes. Higher-priority routes will be placed first. */
98
+ /**
99
+ * React router config option: `strict` routes are sensitive to the presence
100
+ * of a trailing slash.
101
+ */
102
+ strict?: boolean;
103
+ /**
104
+ * Used to sort routes.
105
+ * Higher-priority routes will be matched first.
106
+ */
64
107
  priority?: number;
65
- /** Extra props; will be copied to routes.js. */
108
+ /**
109
+ * Optional route metadata
110
+ */
111
+ metadata?: RouteMetadata;
112
+ /**
113
+ * Extra props; will be available on the client side.
114
+ */
66
115
  [propName: string]: unknown;
67
116
  };
68
117
 
@@ -70,7 +119,7 @@ export type RouteContext = {
70
119
  /**
71
120
  * Plugin-specific context data.
72
121
  */
73
- data?: object | undefined;
122
+ data?: {[key: string]: unknown};
74
123
  };
75
124
 
76
125
  /**