From ee9dfedf915bb19a0e16235fb01db26a90c7d36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benny=20Powers=20-=20=D7=A2=D7=9D=20=D7=99=D7=A9=D7=A8?= =?UTF-8?q?=D7=90=D7=9C=20=D7=97=D7=99!?= Date: Wed, 18 Sep 2024 12:33:07 +0300 Subject: [PATCH] docs: simplify installation tabs (#1690) * docs: simplify installation tabs * docs: fix import map on installation page * docs: jspm import maps * docs: no pfe version * docs: install tabs * chore: patch prism-esm see if that lets build complete see https://github.com/KonnorRogers/prism-esm/pull/3 * docs: fail more gracefully when JSPM can't cope * chore: lint nonsense * docs: link to install info * docs: installation tabs styles --- .../shortcodes/renderInstallation.cjs | 201 +++++++----------- .../elements/uxdot-installation-tabs.ts | 3 + docs/get-started/developers/installation.md | 104 +++++---- patches/prism-esm+1.29.0-fix.4.patch | 15 ++ 4 files changed, 157 insertions(+), 166 deletions(-) create mode 100644 patches/prism-esm+1.29.0-fix.4.patch diff --git a/docs/_plugins/shortcodes/renderInstallation.cjs b/docs/_plugins/shortcodes/renderInstallation.cjs index d6eadd30be..cdf25c51bf 100644 --- a/docs/_plugins/shortcodes/renderInstallation.cjs +++ b/docs/_plugins/shortcodes/renderInstallation.cjs @@ -1,9 +1,26 @@ -/** @typedef {import('@patternfly/pfe-tools/11ty/DocsPage').DocsPage} DocsPage */ +// for editor highlighting +const html = String.raw; +const markdown = String.raw; + +async function generateImportMap(packageName, tagName) { + const { Generator } = await import('@jspm/generator'); + const generator = new Generator({ + providers: { + '@rhds/elements': 'jspm.io', + [packageName]: 'jspm.io', + }, + }); + await generator.install(`${packageName}/${tagName}/${tagName}.js`); + return JSON.stringify(generator.getMap(), null, 2); +} /** * @param {string} content + * @param {object} [options] + * @param {boolean} [options.lightdomcss] + * @param {string} [options.cdnVersion] */ -function renderInstall(content, { +async function renderInstall(content, { lightdomcss = false, cdnVersion = 'v1-alpha', } = {}) { @@ -11,141 +28,52 @@ function renderInstall(content, { * NB: since the data for this shortcode is no a POJO, * but a DocsPage instance, 11ty assigns it to this.ctx._ * @see https://github.com/11ty/eleventy/blob/bf7c0c0cce1b2cb01561f57fdd33db001df4cb7e/src/Plugins/RenderPlugin.js#L89-L93 - * @type {DocsPage} */ const docsPage = this.ctx.doc; - const lightdomcssblock = /* md */` -### Lightdom CSS - -Lightdom CSS is required for this element to ensure a reduced -[Cumulative Layout Shift (CLS)][cls] experience before the element has -fully initialized. - `; + const packageVersion = require('../../../package.json').version; - return /* md */` - - - + const cdnContent = markdown` -
+~~~html + +~~~ - ## Installation ${!docsPage.manifest?.packageJson ? '' : /* md */` - - -Red Hat CDN - - -

CDN Prerelease

-

We are currently working on our CDN, which will be soon moving - into beta. This will be the preferred method of installation in - the near future. If you are a Red Hat associate and have questions - or comments about the CDN or installation process please join us - in our Red Hat Design System Google chat.

-

In the meantime, install this component using npm

-
- -The recommended way to load RHDS is via the Red Hat Digital Experience CDN, -and using an [import map][import-maps]. - -If you have full control over the page you are using, add an import map -to the \`\`, pointing to the CDN, or update any existing import map. -If you are not responsible for the page's \`\`, request that the -page owner makes the change on your behalf. +
Import Map Example ~~~html ~~~ -Once the import map is established, you can load the element with the following -module, containing a [bare module specifier][bare-specifier]: +
-~~~html - -~~~ - -Note that Modules may be placed in the \`\`: since they are deferred by default, -they will not block rendering. +`; -${!lightdomcss ? '' : /* md */`${lightdomcssblock} - -~~~html - -~~~ - -`} -
-NPM - - -Install RHDS using your team's preferred NPM package manager, e.g. + const npmContent = markdown` ~~~shell -npm install ${docsPage.manifest.packageJson.name} -~~~ - -Once that's been accomplished, you will need to use a bundler to resolve -the bare module specifiers and optionally optimize the package for your -site's particular use case and needs. Comprehensive guides to bundling are -beyond the scope of this page; read more about bundlers on their websites: - -- [Rollup][rollup] -- [esbuild][esbuild] -- [Parcel][parcel] -- [Webpack][webpack] - -${!lightdomcss ? '' : /* md */`${lightdomcssblock} - -~~~html - +npm install @rhds/elements ~~~ -Replace \`/path/to\` in the \`href\` attribute with the installation path -to the \`${docsPage.tagName}\` directory in your project. - - `} - -JSPM - - -

Public CDNs

-

JSPM and other public CDNs should not be used on corporate domains. - Use them for development purposes only!

-
- -Add an [import map][import-maps] to the \`\`, pointing to the CDN, -or update any existing import map. - ~~~html - ~~~ -Once the import map is established, you can load the element with the following -module, containing a [bare module specifier][bare-specifier]: +`; + + let jspmContent = ''; + try { + jspmContent = markdown` ~~~html ~~~ -Note that Modules may be placed in the \`\`: since they are deferred by default, -they will not block rendering. - -${!lightdomcss ? '' : /* md */ `${lightdomcssblock} +
Import Map Example ~~~html - + ~~~ -`} - - +
+`; + } catch (error) { + // eslint-disable-next-line no-console + console.error(error); + jspmContent = `Could not generate import map using JSPM: ${error.message}`; + } -${content ?? ''}`} + return html` + -
+ -[import-maps]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap -[bare-specifier]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules -[rollup]: https://rollupjs.org/ -[esbuild]: https://esbuild.github.io/ -[parcel]: https://parceljs.org/ -[webpack]: https://webpack.js.org/ -[cls]: https://web.dev/cls/ +
+

Installation

+

Learn more about how to install on our getting started docs.

+ + Red Hat CDN + ${cdnContent} + NPM + ${npmContent} + JSPM + ${jspmContent} + + +${content ?? ''} - `; +
+`; } module.exports = function(eleventyConfig) { diff --git a/docs/assets/javascript/elements/uxdot-installation-tabs.ts b/docs/assets/javascript/elements/uxdot-installation-tabs.ts index f44714166e..88ea6b9f1b 100644 --- a/docs/assets/javascript/elements/uxdot-installation-tabs.ts +++ b/docs/assets/javascript/elements/uxdot-installation-tabs.ts @@ -23,6 +23,9 @@ export class InstallationTabs extends RhTabs { this.querySelectorAll('rh-tab'), x => x.updateComplete, )); + for (const pre of this.querySelectorAll('rh-tab-panel > pre')) { + pre.style.maxWidth = '100cqw'; + } if (InstallationTabs.stored !== null) { const index = parseInt(InstallationTabs.stored); if (!Number.isNaN(index) diff --git a/docs/get-started/developers/installation.md b/docs/get-started/developers/installation.md index 62ae4fc365..9f451bfc17 100644 --- a/docs/get-started/developers/installation.md +++ b/docs/get-started/developers/installation.md @@ -12,44 +12,51 @@ subnav: ## How to install -There are three ways you can install the Red Hat Design System's web components: CDN, NPM, or JSPM. Each element's "Code" page includes the same installation information with code snippets that are specific to that element. - +There are three ways you can install the Red Hat Design System's web components: +CDN, NPM, or JSPM. Each element's "Code" page includes the same installation +information with code snippets that are specific to that element. ### Red Hat CDN

CDN Prerelease

-

We are currently working on our CDN, which will be soon moving into beta. This will be the preferred method of installation in the near future. If you are a Red Hat associate and have questions or comments about the CDN or installation process please connect with us on Slack.

+

We are currently working on our CDN, which will be soon moving into beta. + This will be the preferred method of installation in the near future. If you + are a Red Hat associate and have questions or comments about the CDN or + installation process please connect with us on Slack.

-The recommended way to load RHDS is via the Red Hat Digital Experience CDN, and using an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap). +The recommended way to load RHDS is via the Red Hat Digital Experience CDN, and +using an [import map][importmap]. -If you have full control over the page you are using, add an import map to the ``, pointing to the CDN, or update any existing import map. If you are not responsible for the page's ``, request that the page owner makes the change on your behalf. +If you have full control over the page you are using, add an import map to the +``, pointing to the CDN, or update any existing import map. If you are not +responsible for the page's ``, request that the page owner makes the +change on your behalf. - + < -Once the import map is established, you can load the element with the following module, containing a [bare module specifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). The example below shows how you'd load in <`rh-button>`. +Once the import map is established, you can load the element with the following +module, containing a [bare module specifier][barespec]. The example below shows +how you'd load in <`rh-button>`. - + < -Note that modules may be placed in the ``. Since they are deferred by default, they will not block rendering. +Note that modules may be placed in the ``. Since they are deferred by +default, they will not block rendering. ### NPM @@ -57,54 +64,77 @@ Note that modules may be placed in the ``. Since they are deferred by defa Install RHDS using your team's preferred NPM package manager. - + -Once that's been accomplished, you will need to use a bundler to resolve the bare module specifiers and optionally optimize the package for your site's particular use case and needs. Comprehensive guides to bundling are beyond the scope of this page; read more about bundlers on their websites: +Once that's been accomplished, you will need to use a bundler to resolve the +bare module specifiers and optionally optimize the package for your site's +particular use case and needs. Comprehensive guides to bundling are beyond the +scope of this page; read more about bundlers on their websites: -- [Rollup](https://rollupjs.org/) -- [esbuild](https://esbuild.github.io/) -- [Parcel](https://parceljs.org/) -- [Webpack](https://webpack.js.org/) +- [Rollup][rollup] +- [esbuild][esbuild] +- [Parcel][parcel] +- [Webpack][webpack] ### JSPM

Public CDNs

-

JSPM and other public CDNs should not be used on corporate domains. Use them for development purposes only!

+

JSPM and other public CDNs should not be used on corporate domains. Use + them for development purposes only!

-Add an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) to the ``, pointing to the CDN, or update any existing import map. +Add an [import map][importmap] to the ``, pointing to the CDN, or update +any existing import map. - + < -Once the import map is established, you can load the element with the following module, containing a [bare module specifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). The example below shows how you'd load in <`rh-button>`. +Once the import map is established, you can load the element with the following +module, containing a [bare module specifier][barespec]. The example below shows +how you'd load in <`rh-button>`. - -Note that Modules may be placed in the ``. Since they are deferred by default, they will not block rendering. +Note that Modules may be placed in the ``. Since they are deferred by +default, they will not block rendering. + +### Lightdom CSS + +Some elements require you to load "Lightdom CSS" stylesheets. This can also help +to reduce [Cumulative Layout Shift (CLS)][cls] experience before the element has +fully initialized. + +```html + +```

Designers

-

To get started using our design system as a designer, go to the Designers page.

+

To get started using our design system as a designer, go to the Designers page.

+ +[rollup]: https://rollupjs.org/ +[esbuild]: https://esbuild.github.io/ +[parcel]: https://parceljs.org/ +[webpack]: https://webpack.js.org/ +[importmap]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap +[barespec]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules +[cls]: https://web.dev/cls/ diff --git a/patches/prism-esm+1.29.0-fix.4.patch b/patches/prism-esm+1.29.0-fix.4.patch new file mode 100644 index 0000000000..bf25dddaf7 --- /dev/null +++ b/patches/prism-esm+1.29.0-fix.4.patch @@ -0,0 +1,15 @@ +diff --git a/node_modules/prism-esm/package.json b/node_modules/prism-esm/package.json +index 077879d..a56a67e 100644 +--- a/node_modules/prism-esm/package.json ++++ b/node_modules/prism-esm/package.json +@@ -4,6 +4,10 @@ + "description": "A prism fork intended for ESM", + "type": "module", + "main": "prism.js", ++ "exports": { ++ ".": "./prism.js", ++ "./*": "./*" ++ }, + "style": "themes/prism.css", + "engines": { + "node": ">=6"