@patternfly/documentation-framework 2.0.0-alpha.6 → 2.0.0-alpha.60

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 (55) hide show
  1. package/CHANGELOG.md +504 -0
  2. package/app.js +12 -12
  3. package/components/autoLinkHeader/autoLinkHeader.css +2 -2
  4. package/components/autoLinkHeader/autoLinkHeader.js +18 -13
  5. package/components/cssVariables/cssSearch.js +3 -4
  6. package/components/cssVariables/cssVariables.css +4 -4
  7. package/components/cssVariables/cssVariables.js +83 -84
  8. package/components/example/example.css +29 -29
  9. package/components/example/example.js +34 -6
  10. package/components/footer/footer.css +16 -16
  11. package/components/footer/footer.js +13 -13
  12. package/components/functionsTable/functionsTable.js +57 -0
  13. package/components/gdprBanner/gdprBanner.css +2 -2
  14. package/components/gdprBanner/gdprBanner.js +3 -3
  15. package/components/inlineAlert/inlineAlert.js +1 -1
  16. package/components/propsTable/propsTable.js +85 -79
  17. package/components/sectionGallery/TextSummary.js +31 -0
  18. package/components/sectionGallery/sectionDataListLayout.js +49 -0
  19. package/components/sectionGallery/sectionGallery.css +53 -0
  20. package/components/sectionGallery/sectionGallery.js +76 -0
  21. package/components/sectionGallery/sectionGalleryLayout.js +39 -0
  22. package/components/sectionGallery/sectionGalleryToolbar.js +38 -0
  23. package/components/sectionGallery/sectionGalleryWrapper.js +105 -0
  24. package/components/sideNav/sideNav.css +12 -12
  25. package/components/sideNav/sideNav.js +41 -13
  26. package/components/tableOfContents/tableOfContents.css +17 -17
  27. package/helpers/codesandbox.js +2 -2
  28. package/helpers/getTitle.js +2 -2
  29. package/layouts/sideNavLayout/sideNavLayout.css +7 -11
  30. package/layouts/sideNavLayout/sideNavLayout.js +57 -40
  31. package/package.json +28 -25
  32. package/pages/404/404.css +2 -2
  33. package/pages/404/index.js +1 -1
  34. package/pages/global-css-variables.md +16 -16
  35. package/routes.js +20 -8
  36. package/scripts/cli/build.js +6 -0
  37. package/scripts/cli/cli.js +2 -0
  38. package/scripts/cli/generate.js +2 -2
  39. package/scripts/cli/start.js +6 -8
  40. package/scripts/md/parseMD.js +46 -11
  41. package/scripts/md/styled-tags.js +8 -4
  42. package/scripts/tsDocgen.js +119 -91
  43. package/scripts/typeDocGen.js +209 -0
  44. package/scripts/webpack/webpack.base.config.js +34 -32
  45. package/scripts/webpack/webpack.client.config.js +11 -8
  46. package/scripts/webpack/webpack.server.config.js +8 -5
  47. package/scripts/writeScreenshots.js +3 -3
  48. package/templates/html.ejs +2 -4
  49. package/templates/mdx.css +156 -161
  50. package/templates/mdx.js +122 -51
  51. package/templates/patternfly-docs/content/extensions/extension/design-guidelines/design-guidelines.md +2 -0
  52. package/templates/patternfly-docs/content/extensions/extension/examples/basic.md +2 -0
  53. package/versions.json +29 -9
  54. package/components/topNav/topNav.css +0 -30
  55. package/pages/red-hat-font.md +0 -40
@@ -0,0 +1,209 @@
1
+ const TypeDoc = require("typedoc");
2
+ const path = require("path");
3
+
4
+ /** Compiles variable types if a type is generic. */
5
+ function getVariableType(typeArguments) {
6
+ if (!typeArguments || typeArguments.length === 0) {
7
+ return "";
8
+ }
9
+
10
+ const typeArgs = typeArguments.map((type) => getType(type));
11
+
12
+ return (
13
+ typeArgs.reduce((acc, type) => acc + type + ", ", "<").slice(0, -2) + ">"
14
+ );
15
+ }
16
+
17
+ /** compiles key/value pairs of a Type or Interface. */
18
+ function getPropertyTypes(properties) {
19
+ const formattedProperties = properties.reduce((acc, property) => {
20
+ const { flags, name, type } = property;
21
+ const formattedName = flags.isOptional ? name + "?" : name;
22
+ return `${acc}${formattedName}: ${getType(type)}; `;
23
+ }, "");
24
+
25
+ return `{ ${formattedProperties} }`;
26
+ }
27
+
28
+ /** Compiles the subtypes of a tuple. */
29
+ function getTupleTypes(tupleElements) {
30
+ const [firstType, secondType] = tupleElements.map((element) =>
31
+ getType(element)
32
+ );
33
+ return `[${firstType}, ${secondType}]`;
34
+ }
35
+
36
+ /** Compiles the different subtypes of a union or intersection. */
37
+ function getJoinedTypes(types, joinChar) {
38
+ const joinedTypes = types.map((type) => getType(type));
39
+ return joinedTypes
40
+ .reduce((acc, type) => `${acc} ${joinChar} ${type}`, "")
41
+ .slice(2);
42
+ }
43
+
44
+ /** Return the type of a reflection.
45
+ * For anything that has, or can have, multiple subtypes (i.e. variable types in a generic, properties in an interface,
46
+ * several types in a union, callbacks, etc.) it will recursively navigate the parsed type info as needed to resolve
47
+ * all relevant subtypes.
48
+ */
49
+ function getType(reflection) {
50
+ switch (reflection.type) {
51
+ case "intrinsic":
52
+ case "reference":
53
+ return reflection.name + getVariableType(reflection.typeArguments);
54
+ case "union":
55
+ return getJoinedTypes(reflection.types, "|");
56
+ case "reflection":
57
+ const { signatures, children } = reflection.declaration;
58
+ if (signatures) {
59
+ return getFunctionDocumentation(signatures[0]).type;
60
+ } else if (children) {
61
+ return getPropertyTypes(children);
62
+ } else {
63
+ return "Props";
64
+ }
65
+ case "array":
66
+ return reflection.elementType.name + "[]";
67
+ case "tuple":
68
+ return getTupleTypes(reflection.elements);
69
+ case "intersection":
70
+ return getJoinedTypes(reflection.types, "&");
71
+ case "literal":
72
+ return reflection.value;
73
+ }
74
+ }
75
+
76
+ /** Compiles information about the parameters of a function.
77
+ * Includes the name, default value, type, and whether it is optional.
78
+ */
79
+ function getParamInfo(parameters = []) {
80
+ return parameters.map((parameter) => {
81
+ const { name, defaultValue, type, flags } = parameter;
82
+ return {
83
+ name,
84
+ default: defaultValue,
85
+ type: getType(type),
86
+ optional: flags.isOptional,
87
+ };
88
+ });
89
+ }
90
+
91
+ /** Formats call signature for a function. */
92
+ function formatFunctionType(parameters, returnType) {
93
+ const annotatedParams = parameters.map((parameter) => {
94
+ const { name, type, optional } = parameter;
95
+
96
+ return [optional ? name + "?" : name, type];
97
+ });
98
+
99
+ const formattedParams = annotatedParams
100
+ .reduce((acc, param) => `${acc}, ${param[0]}: ${param[1]}`, "")
101
+ .slice(2);
102
+
103
+ return `(${formattedParams}) => ${returnType}`;
104
+ }
105
+
106
+ /** Primary entry point for gathering type information from a typedoc function reflection. */
107
+ function getFunctionDocumentation(callSignatureReflection) {
108
+ const { type, parameters, comment } = callSignatureReflection;
109
+ const params = getParamInfo(parameters);
110
+
111
+ const returnType = type?.name || getType(type);
112
+
113
+ return {
114
+ params,
115
+ returnType,
116
+ type: formatFunctionType(params, returnType),
117
+ description: comment?.shortText,
118
+ };
119
+ }
120
+
121
+ /** Parses the source for a package using TypeDoc. */
122
+ function typeDocGen(entryPoint, tsconfigLocation) {
123
+ const app = new TypeDoc.Application();
124
+ app.options.addReader(new TypeDoc.TSConfigReader());
125
+ app.bootstrap({
126
+ // typedoc options here
127
+ entryPointStrategy: "expand",
128
+ entryPoints: [entryPoint],
129
+ tsconfig: tsconfigLocation,
130
+ });
131
+
132
+ // this non-standard reflection creation allows us to ignore any type errors in a package
133
+ const project = app.converter.convert(app.getEntryPoints() ?? []);
134
+
135
+ // if something caused project conversion to fail log an error
136
+ if (project) {
137
+ return project;
138
+ } else {
139
+ console.error("Something went wrong during typedoc project conversion");
140
+ return {};
141
+ }
142
+ }
143
+
144
+ /** Takes package information and returns an object with all tsdoc standard format info about the functions in it.
145
+ *
146
+ * The object has file names as keys, with values being an additional object which has the function names in that file
147
+ * as keys and the information about that function as the value, also in object form.
148
+ * Information includes the name of the file in which it's defined, the parameters, description, default values and
149
+ * type information.
150
+ *
151
+ * Example structure:
152
+ * {
153
+ * "components/component.tsx": {
154
+ * "boolToString": {
155
+ * "description": "Converts a boolean to a string",
156
+ * "params": [
157
+ * {
158
+ * "default": false,
159
+ * "name": "booleanValue",
160
+ * "optional": true,
161
+ * "type": "boolean",
162
+ * },
163
+ * ],
164
+ * "returnType": "string",
165
+ * "type": "(booleanValue?: boolean) => string",
166
+ * },
167
+ * },
168
+ * }
169
+ */
170
+ function getPackageFunctionDocumentation(
171
+ packageName,
172
+ pathToRoot = "dist/js/index.js",
173
+ srcPath = "src",
174
+ tsconfigPath = "tsconfig.json"
175
+ ) {
176
+ const packageRoot = require.resolve(packageName).replace(pathToRoot, "");
177
+ const entry = path.relative(process.cwd(), path.join(packageRoot, srcPath));
178
+ const configLocation = path.relative(
179
+ process.cwd(),
180
+ path.join(packageRoot, tsconfigPath)
181
+ );
182
+
183
+ const packageReflection = typeDocGen(entry, configLocation);
184
+
185
+ // 64 corresponds with functions, see all reflection kinds here: https://typedoc.org/api/enums/Models.ReflectionKind-1.html
186
+ const functionReflections = packageReflection.getReflectionsByKind(64);
187
+
188
+ const functionsMap = functionReflections.reduce((acc, functionReflection) => {
189
+ const { name, sources, signatures } = functionReflection;
190
+
191
+ const sourceFile = sources[0].fileName;
192
+ const shortSourceFile = sourceFile.replace(
193
+ `${packageName}/${srcPath}/`,
194
+ ""
195
+ );
196
+ const obj = getFunctionDocumentation(signatures[0]);
197
+
198
+ if (acc[shortSourceFile]) {
199
+ acc[shortSourceFile] = { ...acc[shortSourceFile], [name]: obj };
200
+ } else {
201
+ acc[shortSourceFile] = { [name]: obj };
202
+ }
203
+ return acc;
204
+ }, {});
205
+
206
+ return functionsMap;
207
+ }
208
+
209
+ module.exports = { getPackageFunctionDocumentation };
@@ -8,6 +8,7 @@ module.exports = (_env, argv) => {
8
8
  const {
9
9
  pathPrefix = '',
10
10
  mode,
11
+ googleAnalyticsID = false,
11
12
  algolia = {},
12
13
  hasGdprBanner = false,
13
14
  hasFooter = false,
@@ -27,7 +28,8 @@ module.exports = (_env, argv) => {
27
28
  output: {
28
29
  publicPath: isProd ? `${pathPrefix}/` : '/',
29
30
  pathinfo: false, // https://webpack.js.org/guides/build-performance/#output-without-path-info,
30
- hashDigestLength: 8
31
+ hashDigestLength: 8,
32
+ clean: true, // Clean the output directory before emit.
31
33
  },
32
34
  amd: false, // We don't use any AMD modules, helps performance
33
35
  mode: isProd ? 'production' : 'development',
@@ -39,9 +41,12 @@ module.exports = (_env, argv) => {
39
41
  include: [
40
42
  path.resolve(process.cwd(), 'src'),
41
43
  path.resolve(process.cwd(), 'patternfly-docs'),
44
+ path.resolve(process.cwd(), 'examples'),
42
45
  path.resolve(__dirname, '../..'), // Temporarily compile theme using webpack for development
43
46
  /react-[\w-]+\/src\/.*\/examples/,
44
47
  /react-[\w-]+\\src\\.*\\examples/, // fix for Windows
48
+ /react-[\w-]+\/patternfly-docs\/.*\/examples/, //fixes for extensions
49
+ /react-[\w-]+\\patternfly-docs\\.*\\examples/,
45
50
  ].concat(includePaths.map(path => new RegExp(path))),
46
51
  exclude: [
47
52
  path.resolve(__dirname, '../../node_modules'), // Temporarily compile theme using webpack for development
@@ -82,35 +87,28 @@ module.exports = (_env, argv) => {
82
87
  },
83
88
  {
84
89
  test: /\.(gif|svg)$/,
85
- use: {
86
- loader: 'file-loader',
87
- options: {
88
- name: '[name].[contenthash].[ext]',
89
- outputPath: 'images/'
90
- },
90
+ type: 'asset/resource',
91
+ dependency: { not: ['url'] },
92
+ generator: {
93
+ filename: 'images/[hash][ext][query]'
91
94
  }
92
95
  },
93
96
  {
94
97
  test: /\.(pdf)$/,
95
- use: {
96
- loader: 'file-loader',
97
- options: {
98
- name: '[name].[contenthash].[ext]',
99
- }
98
+ type: 'asset/resource',
99
+ dependency: { not: ['url'] },
100
+ generator: {
101
+ filename: '[hash][ext][query]'
100
102
  }
101
103
  },
102
104
  {
103
105
  test: /.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
104
- use: [
105
- {
106
- loader: 'file-loader',
107
- options: {
108
- name: '[name].[ext]',
109
- outputPath: 'fonts/'
110
- }
111
- }
112
- ]
113
- }
106
+ type: 'asset/resource',
107
+ dependency: { not: ['url'] },
108
+ generator: {
109
+ filename: 'fonts/[name][ext][query]'
110
+ }
111
+ },
114
112
  ]
115
113
  },
116
114
  resolve: {
@@ -118,21 +116,29 @@ module.exports = (_env, argv) => {
118
116
  alias: {
119
117
  'client-styles': path.resolve(process.cwd(), 'patternfly-docs/patternfly-docs.css.js'),
120
118
  './routes-client': path.resolve(process.cwd(), 'patternfly-docs/patternfly-docs.routes.js'),
121
- './routes-generated': path.resolve(process.cwd(), 'patternfly-docs/generated/index.js')
119
+ './routes-generated': path.resolve(process.cwd(), 'patternfly-docs/generated/index.js'),
120
+ process: "process/browser"
122
121
  },
123
122
  modules: [
124
123
  'node_modules',
125
124
  ...module.paths,
126
- ]
125
+ ],
126
+ fallback: {
127
+ "path": require.resolve("path-browserify")
128
+ },
127
129
  },
128
130
  // Use this module's node_modules first (for use in Core/React workspaces)
129
131
  resolveLoader: {
130
132
  modules: module.paths,
131
133
  },
132
134
  plugins: [
135
+ new webpack.ProvidePlugin({
136
+ process: 'process/browser',
137
+ }),
133
138
  new webpack.DefinePlugin({
134
139
  'process.env.NODE_ENV': JSON.stringify(mode),
135
140
  'process.env.pathPrefix': JSON.stringify(isProd ? pathPrefix : ''),
141
+ 'process.env.googleAnalyticsID': JSON.stringify(isProd ? googleAnalyticsID : ''),
136
142
  'process.env.algolia': JSON.stringify(algolia),
137
143
  'process.env.hasGdprBanner': JSON.stringify(hasGdprBanner),
138
144
  'process.env.hasFooter': JSON.stringify(hasFooter),
@@ -143,20 +149,16 @@ module.exports = (_env, argv) => {
143
149
  'process.env.sideNavItems': JSON.stringify(sideNavItems),
144
150
  'process.env.topNavItems': JSON.stringify(topNavItems),
145
151
  'process.env.prnum': JSON.stringify(process.env.CIRCLE_PR_NUMBER || process.env.PR_NUMBER || ''),
146
- 'process.env.prurl': JSON.stringify(process.env.CIRCLE_PULL_REQUEST || ''),
152
+ 'process.env.prurl': JSON.stringify(process.env.CIRCLE_PULL_REQUEST || '')
147
153
  }),
148
154
  new CopyWebpackPlugin({
149
155
  patterns: [
150
156
  { from: path.join(__dirname, '../../assets'), to: 'assets' }
151
157
  ]
152
158
  }),
153
- new MonacoWebpackPlugin(),
154
- ...(isProd
155
- ? [
156
- new CleanWebpackPlugin()
157
- ]
158
- : []
159
- )
159
+ new MonacoWebpackPlugin({
160
+ globalAPI: true,
161
+ })
160
162
  ],
161
163
  stats: 'minimal'
162
164
  };
@@ -5,6 +5,7 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl
5
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
6
  const TerserPlugin = require('terser-webpack-plugin');
7
7
  const CopyPlugin = require('copy-webpack-plugin');
8
+ const webpack = require('webpack');
8
9
  const baseConfig = require('./webpack.base.config');
9
10
  const { getHtmlWebpackPlugins } = require('./getHtmlWebpackPlugins');
10
11
 
@@ -23,18 +24,20 @@ const reactJSRegex = /react-([^\\/]*)[\\/]dist[\\/].*\.js$/
23
24
 
24
25
  const clientConfig = async (env, argv) => {
25
26
  const isProd = argv.mode === 'production';
26
-
27
27
  return {
28
28
  output: {
29
29
  path: argv.output ? path.resolve(argv.output) : path.resolve('public'),
30
- filename: '[name].[hash].bundle.js'
30
+ filename: '[name].[contenthash].bundle.js'
31
31
  },
32
32
  devServer: {
33
33
  hot: true,
34
34
  historyApiFallback: true,
35
+ compress: true,
35
36
  port: argv.port,
36
- clientLogLevel: 'info',
37
- stats: 'minimal'
37
+ client: {
38
+ logging: 'info',
39
+ },
40
+ static: {}
38
41
  },
39
42
  optimization: {
40
43
  splitChunks: {
@@ -71,10 +74,7 @@ const clientConfig = async (env, argv) => {
71
74
  },
72
75
  minimize: isProd ? true : false,
73
76
  minimizer: [
74
- new TerserPlugin({
75
- cache: path.join(process.cwd(), '.cache/terser'),
76
- ...(process.env.CI ? { parallel: 2 } : {})
77
- }),
77
+ new TerserPlugin(),
78
78
  ],
79
79
  runtimeChunk: 'single',
80
80
  },
@@ -113,6 +113,9 @@ const clientConfig = async (env, argv) => {
113
113
  ]
114
114
  },
115
115
  plugins: [
116
+ new webpack.DefinePlugin({
117
+ 'process.env.PRERENDER': false,
118
+ }),
116
119
  new MiniCssExtractPlugin(!isProd ? {} : {
117
120
  filename: '[name].[contenthash].css',
118
121
  chunkFilename: '[name].[contenthash].css',
@@ -2,8 +2,11 @@ const path = require('path');
2
2
  const webpack = require('webpack');
3
3
  const { merge } = require('webpack-merge');
4
4
  const baseConfig = require('./webpack.base.config');
5
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
+ const reactCSSRegex = /(react-[\w-]+\/dist|react-styles\/css)\/.*\.css$/;
5
7
 
6
- const serverConfig = () => {
8
+ const serverConfig = async (env, argv) => {
9
+ const isProd = argv.mode === 'production';
7
10
  return {
8
11
  output: {
9
12
  path: path.resolve('.cache/ssr-build'), // Don't bloat `public` dir
@@ -31,7 +34,7 @@ const serverConfig = () => {
31
34
  {
32
35
  test: /(novnc-core|@novnc\/novnc)\/.*\.js/,
33
36
  use: 'null-loader'
34
- }
37
+ },
35
38
  ]
36
39
  },
37
40
  resolve: {
@@ -41,7 +44,7 @@ const serverConfig = () => {
41
44
  // The maintainer will not allow his bundle to be required from a node context
42
45
  // https://github.com/xtermjs/xterm.js/pull/3134
43
46
  'xterm': '@patternfly/documentation-framework/helpers/xterm',
44
- 'xterm-addon-fit': '@patternfly/documentation-framework/helpers/xterm-addon-fit'
47
+ 'xterm-addon-fit': '@patternfly/documentation-framework/helpers/xterm-addon-fit',
45
48
  },
46
49
  },
47
50
  // Load in prerender.js instead
@@ -49,7 +52,7 @@ const serverConfig = () => {
49
52
  };
50
53
  }
51
54
 
52
- module.exports = (env = {}, argv) => merge(
55
+ module.exports = async (env = {}, argv) => merge(
53
56
  baseConfig(env, argv),
54
- serverConfig(env, argv)
57
+ await serverConfig(env, argv)
55
58
  );
@@ -11,7 +11,7 @@ sharp.cache(false);
11
11
  async function writeScreenshot({ page, data: { url, urlPrefix } }) {
12
12
  await page.goto(url);
13
13
  await page.addStyleTag({content: '*,*::before,*::after{animation-delay:-1ms !important;animation-duration:1ms !important;animation-iteration-count:1 !important;transition-duration:0s !important;transition-delay:0s !important;}'}); // disable animations/transitions so they don't interfere with screenshot tool
14
- await page.waitForSelector('.pf-u-h-100');
14
+ await page.waitForSelector('.pf-v5-u-h-100');
15
15
  const outfile = path.join(
16
16
  screenshotBase,
17
17
  url.replace(`${urlPrefix}/`, '') + '.png'
@@ -27,7 +27,7 @@ async function writeScreenshot({ page, data: { url, urlPrefix } }) {
27
27
  await sharp(buffer).toFile(outfile);
28
28
  }
29
29
 
30
- async function writeScreenshots({ urlPrefix }) {
30
+ async function writeScreenshots({ urlPrefix, allRoutes }) {
31
31
  const cluster = await Cluster.launch({
32
32
  concurrency: Cluster.CONCURRENCY_CONTEXT,
33
33
  maxConcurrency: os.cpus().length,
@@ -43,7 +43,7 @@ async function writeScreenshots({ urlPrefix }) {
43
43
 
44
44
  // Add some pages to queue
45
45
  Object.entries(fullscreenRoutes)
46
- .filter(([, { isFullscreenOnly }]) => isFullscreenOnly)
46
+ .filter(([, { isFullscreenOnly }]) => allRoutes || isFullscreenOnly)
47
47
  .forEach(([url,]) => cluster.queue({
48
48
  url: `${urlPrefix}${url}`,
49
49
  urlPrefix
@@ -15,10 +15,8 @@
15
15
  <meta name="application-name" content="PatternFly docs">
16
16
  <%= htmlWebpackPlugin.tags.headTags %>
17
17
  </head>
18
- <body class="pf-m-redhat-updated-font pf-m-redhatmono-font">
19
- <div id="root">
20
- <%= prerendering %>
21
- </div>
18
+ <body>
19
+ <div id="root"><%= prerendering %></div>
22
20
  <%= htmlWebpackPlugin.tags.bodyTags %>
23
21
  <% if (algolia) { %>
24
22
  <script