diff --git a/.github/workflows/check-markdown.yml b/.github/workflows/check-markdown.yml index b7d2e954a..c7754b461 100644 --- a/.github/workflows/check-markdown.yml +++ b/.github/workflows/check-markdown.yml @@ -9,10 +9,10 @@ jobs: markdown-link-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Use Node from Volta - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 with: node-version-file: 'package.json' cache: 'npm' @@ -26,10 +26,10 @@ jobs: markdown-spelling-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Use Node from Volta - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 with: node-version-file: 'package.json' cache: 'npm' diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index b99937c3f..554ee637f 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,13 +11,13 @@ jobs: runs-on: 'ubuntu-latest' steps: - name: Checkout Code - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 # this overrides previous versions of the node runtime that was set. # jobs that need a different version of the Node runtime should explicitly # set their node version after running this step - name: Use Node Version from Volta - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3 with: node-version-file: './package.json' cache: 'npm' diff --git a/cspell-wordlist.txt b/cspell-wordlist.txt index 785969053..090262807 100644 --- a/cspell-wordlist.txt +++ b/cspell-wordlist.txt @@ -30,6 +30,7 @@ prerenders proxied pseudocode runtimes +shadowrootmode sourcemaps templating transpiles diff --git a/docs/components/api.md b/docs/components/api.md index 174f446d2..6051e207b 100644 --- a/docs/components/api.md +++ b/docs/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/docs/components/component-lifecycle.md b/docs/components/component-lifecycle.md index 377dd6530..72609e476 100644 --- a/docs/components/component-lifecycle.md +++ b/docs/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. @@ -145,7 +145,6 @@ componentWillLoad() { } ``` - ## Example This simple example shows a clock and updates the current time every second. The timer is started when the component is added to the DOM. Once it's removed from the DOM, the timer is stopped. diff --git a/docs/config/01-overview.md b/docs/config/01-overview.md index 8d35ca59b..46e7caa33 100644 --- a/docs/config/01-overview.md +++ b/docs/config/01-overview.md @@ -108,6 +108,47 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + +## generateExportMaps + +*default: `false`* + +Stencil will generate [export maps](https://nodejs.org/api/packages.html#packages_exports) that correspond with various output target outputs. This includes the root +entry point based on the [primary output target](../output-targets/01-overview.md#primary-package-output-target-validation) (or first eligible output target if not specified), +the entry point for the lazy-loader (if using the `dist` output target), and entry points for each component (if using `dist-custom-elements`). + ## globalScript The global script config option takes a file path as a string. @@ -470,3 +511,37 @@ export declare function util(arg: UtilInterface): void; When `true`, validation for common `package.json` fields will occur based on setting an output target's `isPrimaryPackageOutputTarget` flag. For more information on package validation, please see the [output target docs](../output-targets/01-overview.md#primary-package-output-target-validation). + +## rollupConfig + +Passes custom configuration down to rollup itself. The following options can be overwritten: + +- `inputOptions`: [`context`](https://rollupjs.org/configuration-options/#context), [`external`](https://rollupjs.org/configuration-options/#external), [`moduleContext`](https://rollupjs.org/configuration-options/#modulecontext) [`treeshake`](https://rollupjs.org/configuration-options/#treeshake) +- `outputOptions`: [`globals`](https://rollupjs.org/configuration-options/#output-globals) + +*default: `{}`* + +## watchIgnoredRegex + +*default: `[]`* + +*type: `RegExp | RegExp[]`* + +A regular expression (or array of regular expressions) that can be used to omit files from triggering a rebuild in watch mode. During compile-time, each file in the Stencil +project will be tested against each regular expression to determine if changes to the file (or directory) should trigger a project rebuild. + +:::note +If you want to ignore TS files such as `.ts`/`.js` or `.tsx`/`.jsx` extensions, these files will also need to be specified in your project's tsconfig's +[`watchOptions`](https://www.typescriptlang.org/docs/handbook/configuring-watch.html#configuring-file-watching-using-a-tsconfigjson) _in addition_ to the +`watchIgnoredRegex` option. For instance, if we wanted to ignore the `my-component.tsx` file, we'd specify: + +```json title="tsconfig.json" +{ + ..., + "watchOptions": { + "excludeFiles": ["src/components/my-component/my-component.tsx"] + } +} +``` + +::: diff --git a/docs/config/extras.md b/docs/config/extras.md index e73e05eae..bfed8bfac 100644 --- a/docs/config/extras.md +++ b/docs/config/extras.md @@ -130,6 +130,10 @@ An experimental flag that when set to `true`, aligns the behavior of invoking th ### scriptDataOpts +:::caution +This option has been deprecated and will be removed in the next major Stencil release. +::: + It is possible to assign data to the actual ` + + + + + + +``` diff --git a/docs/guides/hydrate-app.md b/docs/guides/hydrate-app.md index d02fe0b1b..37fd5c7af 100644 --- a/docs/guides/hydrate-app.md +++ b/docs/guides/hydrate-app.md @@ -37,14 +37,10 @@ After publishing your component library, you can import the hydrate app into your server's code like this: ```javascript -import { hydrateDocument } from 'yourpackage/hydrate'; +import { hydrateDocument, renderToString, streamToString } from 'yourpackage/hydrate'; ``` -The hydrate app module exports two functions, `hydrateDocument` and -`renderToString`. `hydrateDocument` takes a -[document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) as -its input while `renderToString` takes a raw HTML string. Both functions return -a Promise which wraps a result object. +The hydrate app module exports 3 functions, `hydrateDocument`, `renderToString` and `streamToString`. `hydrateDocument` takes a [document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) as its input while `renderToString` as well as `streamToString` takes a raw HTML string. While `hydrateDocument` and `renderToString` return a Promise which wraps a result object, `streamToString` returns a [`Readable`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) stream that can be passed into a server response. ### hydrateDocument @@ -97,21 +93,156 @@ the hydrated HTML can be found under the `html` property. *Example taken from Ionic Core* ```javascript -const results = await hydrate.renderToString(srcHtml, { - prettyHtml: true, - removeScripts: true -}); +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ ``` #### renderToString Options - - `approximateLineWidth` - number - - `prettyHtml` - boolean - - `removeAttributeQuotes` - boolean - - `removeBooleanAttributeQuotes` - boolean - - `removeEmptyAttributes` - boolean - - `removeHtmlComments` - boolean - - `afterHydrate` - boolean - - `beforeHydrate` - boolean +##### `approximateLineWidth` + +__Type:__ `number` + +Determines when line breaks are being set when serializing the component. + +##### `prettyHtml` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` it prettifies the serialized HTML code, intends elements and escapes text nodes. + +##### `removeAttributeQuotes` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes attribute quotes when possible, e.g. replaces `someAttribute="foo"` to `someAttribute=foo`. + +##### `removeEmptyAttributes` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true` it removes attribute that don't have values, e.g. remove `class=""`. + +##### `removeHtmlComments` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes any abundant HTML comments. Stencil still requires to insert hydration comments to be able to reconcile the component. + +##### `beforeHydrate` + +__Type:__ `(document: Document, url: URL) => | Promise` + +Allows to modify the document and all its containing components to be modified before the hydration process starts. + +##### `afterHydrate` + +__Type:__ `(document: Document, url: URL, results: PrerenderUrlResults) => | Promise` + +Allows to modify the document and all its containing components after the component was rendered in the virtual DOM and before the serialization process starts. + +##### `serializeShadowRoot` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` Stencil will render a component defined with a `shadow: true` flag into a [Declarative Shadow DOM](https://developer.chrome.com/docs/css-ui/declarative-shadow-dom), e.g.: + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ +``` + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: false, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + *
+ * + * Hello, World! I'm Stencil 'Don't call me a framework' JS + *
+ *
+ * ``` + */ +``` + +If set to `false` it renders the component as scoped component. + +##### `fullDocument` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true`, Stencil will serialize a complete HTML document for a server to respond. If set to `false` it will only render the components within the given template. diff --git a/docs/output-targets/copy-tasks.md b/docs/output-targets/copy-tasks.md index 0b3340791..c946f92c3 100644 --- a/docs/output-targets/copy-tasks.md +++ b/docs/output-targets/copy-tasks.md @@ -21,6 +21,69 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `ignore` + +An optional array of glob patterns to exclude from the copy operation. + +__Type:__ `string[]` + +__Default:__ `['**\/__mocks__/**', '**\/__fixtures__/**', '**\/dist/**', '**\/.{idea,git,cache,output,temp}/**', '.ds_store', '.gitignore', 'desktop.ini', 'thumbs.db']` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/docs/reference/support-policy.md b/docs/reference/support-policy.md index e15615a54..9cbc6428a 100644 --- a/docs/reference/support-policy.md +++ b/docs/reference/support-policy.md @@ -86,6 +86,7 @@ The table below describes recent versions of Stencil and the version of TypeScri | Stencil Version | TypeScript Version | |:---------------:|:------------------:| +| v4.20.0 | v5.5.3 | | v4.16.0 | v5.4.5 | | v4.15.0 | v5.4.4 | | v4.14.0 | v5.4.3 | @@ -124,12 +125,12 @@ compatibility tables to describe the interoperability requirements of these piec ### JavaScript Runtime -| Stencil Version | Node v10 | Node v12 | Node v14 | Node v16 | Node v18 | Node v20 | -|:---------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| -| V4 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | -| V3 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | -| V2 | ❌ | ✅ | ✅ | ✅ | ⚠ | ❌ | -| V1 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | +| Stencil Version | Node v10 | Node v12 | Node v14 | Node v16 | Node v18 | Node v20 | Node v22 | +|:---------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| +| V4 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| V3 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | +| V2 | ❌ | ✅ | ✅ | ✅ | ⚠ | ❌ | ❌ | +| V1 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ### Testing Libraries diff --git a/docs/testing/03-vitest.md b/docs/testing/03-vitest.md new file mode 100644 index 000000000..a1395f24c --- /dev/null +++ b/docs/testing/03-vitest.md @@ -0,0 +1,180 @@ +--- +title: Vitest +position: 5 +--- + +# Overview + +[Vitest](https://vitest.dev/) is a popular and modern test framework for unit testing. You can use Vitest to test Stencil components in the browser using its [browser mode feature](https://vitest.dev/guide/browser.html). + +:::caution +Vitest browser mode is an experimental feature and in early development. As such, it may not yet be fully optimized, and there may be some bugs or issues that have not yet been ironed out. +::: + +## Set Up + +To get started with Vitest, all you need to install it via: + +```bash npm2yarn +npm install vitest @vitest/browser unplugin-stencil webdriverio +``` + +This command installs: + +- `vitest`: the core test framework +- `@vitest/browser`: enables testing in browser environments +- `unplugin-stencil`: integrates Stencil's compiler with Vitest for seamless testing +- `webdriverio`: facilitates browser management for tests + +Next, we create a Vitest configuration as following: + +```ts title="vitest.config.ts" +import stencil from 'unplugin-stencil/vite' +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + browser: { + enabled: true, + headless: true, + name: 'chrome' + }, + }, + plugins: [stencil()] +}) +``` + +This configuration enables tests to run in a headless Chrome browser. + +## Writing Tests + +Once you've setup Vitest you can start write your first test. In order to render a Stencil component into the browser, all you need to do is import the component and initiate an instance of the component on the page: + +```ts title="src/components/my-component/my-component.test.ts" +import { expect, test } from 'vitest' + +import '../src/components/my-component/my-component.js' + +test('should render component correctly', async () => { + const cmp = document.createElement('my-component') + cmp.setAttribute('first', 'Stencil') + cmp.setAttribute('last', `'Don't call me a framework' JS`) + document.body.appendChild(cmp) + + await new Promise((resolve) => requestIdleCallback(resolve)) + expect(cmp.shadowRoot?.querySelector('div')?.innerText) + .toBe(`Hello, World! I'm Stencil 'Don't call me a framework' JS`) +}) +``` + +Lastly, let's add a Vitest script to our `package.json`: + +```json +{ + "scripts": { + "test": "vitest --run" + }, +} +``` + +Execute the tests using: + +```bash npm2yarn +npm test +``` + +Expected output: + +``` +❯ npm test + +> vitest@1.0.0 test +> vitest --run + +The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. + + RUN v1.5.0 /private/tmp/vitest + Browser runner started at http://localhost:5173/ + +[19:39.9] build, vitest, prod mode, started ... +[19:39.9] transpile started ... +[19:40.0] transpile finished in 72 ms +[19:40.0] generate custom elements + source maps started ... +[19:40.1] generate custom elements + source maps finished in 137 ms +[19:40.1] build finished in 227 ms + + ✓ src/components/my-component/my-component.test.ts (1) + ✓ should render component correctly + + Test Files 1 passed (1) + Tests 1 passed (1) + Start at 14:19:36 + Duration 3.19s (transform 0ms, setup 0ms, collect 721ms, tests 22ms, environment 0ms, prepare 0ms) + +``` + +### Use JSX + +The example above creates the Stencil instance using basic DOM primitives. If you prefer to use JSX also for rendering Stencil components in your test, just create a `jsx.ts` utility file with the following content: + +```ts title="src/utils/jsx.ts" +export const createElement = (tag, props, ...children) => { + if (typeof tag === 'function') { + return tag(props, ...children) + } + const element = document.createElement(tag) + + Object.entries(props || {}).forEach(([name, value]) => { + if (name.startsWith('on') && name.toLowerCase() in window) { + element.addEventListener(name.toLowerCase().substr(2), value) + } else { + element.setAttribute(name, value.toString()) + } + }) + + children.forEach((child) => { + appendChild(element, child) + }) + + return element +} + +export const appendChild = (parent, child) => { + if (Array.isArray(child)) { + child.forEach((nestedChild) => appendChild(parent, nestedChild)) + } else { + parent.appendChild(child.nodeType ? child : document.createTextNode(child)) + } +} + +export const createFragment = (_, ...children) => { + return children +} +``` + +Now update your test, import the `createElement` method and tell the JSX engine to use that method for rendering the JSX snippet. Our test should look as follows: + +```tsx title="src/components/my-component/my-component.test.tsx" +/** @jsx createElement */ +import { expect, test } from 'vitest' + +import { createElement } from '../../utils/jsx' +import './my-component.js' + +test('should render the component with jsx', async () => { + const cmp = + document.body.appendChild(cmp) + await new Promise((resolve) => requestIdleCallback(resolve)) + expect(cmp.shadowRoot?.querySelector('div')?.innerText) + .toBe(`Hello, World! I'm Stencil 'Don't call me a framework' JS`) +}) +``` + +__Note:__ the `/** @jsx createElement */` at the top of the file tells JSX which rendering function it should use to parse the JSX snippet. + +## Limitations + +Be aware of the following limitations, when using Vitest as test framework for testing Stencil components: + +- __Mocking not yet supported__: you can't mock any files or dependencies when running with the Stencil browser feature +- __No auto-waits__: in order to ensure that the component is rendered, you have to manually wait via, e.g. calling `await new Promise((resolve) => requestIdleCallback(resolve))` \ No newline at end of file diff --git a/docs/testing/playwright/_category_.json b/docs/testing/playwright/_category_.json index f079d5f3d..ed1efac38 100644 --- a/docs/testing/playwright/_category_.json +++ b/docs/testing/playwright/_category_.json @@ -1,3 +1,4 @@ { - "label": "Playwright" + "label": "Playwright", + "position": 2 } diff --git a/docs/testing/stencil-testrunner/03-unit-testing.md b/docs/testing/stencil-testrunner/03-unit-testing.md index 904c76a60..94af7305d 100644 --- a/docs/testing/stencil-testrunner/03-unit-testing.md +++ b/docs/testing/stencil-testrunner/03-unit-testing.md @@ -18,7 +18,6 @@ In order to unit test a component as rendered HTML, tests can use `newSpecPage() Below is a simple example where `newSpecPage()` is given one component class which was imported, and the initial HTML to use for the test. In this example, when the component `MyCmp` renders it sets its text content as "Success!". The matcher `toEqualHtml()` is then used to ensure the component renders as expected. - ```typescript import { newSpecPage } from '@stencil/core/testing'; import { MyCmp } from '../my-cmp'; @@ -35,8 +34,8 @@ it('should render my component', async () => { ``` The example below uses the template option to test the component -```tsx -// mycmp.spec.tsx + +```tsx title="mycmp.spec.tsx" // Since the 'template' argument to `newSpecPage` is using jsx syntax, this should be in a .tsx file. import { h } from '@stencil/core'; import { newSpecPage } from '@stencil/core/testing'; @@ -52,9 +51,47 @@ it('should render my component', async () => { Hello World `); }); +``` + +You render functional components without defining them in the `components` list, e.g.: + +```tsx title="mycmp.spec.tsx" +import { Fragment, h } from '@stencil/core'; +import { newSpecPage } from '@stencil/core/testing'; +import { MyFunctionalComponent } from '../my-functional-cmp'; + +it('should render my component', async () => { + /** + * or define functional components directly in your test + */ + const AnotherFunctionalComponent = (props: any, children: typeof Fragment) => ( +
{children}
+ ); + const page = await newSpecPage({ + components: [], + template: () => ( + + Hello World! + + ), + }); + expect(page.root).toEqualHtml(` +
+
+ Hello World! +
+
+ `); +}); ``` +:::note + +Declaring Stencil class components directly within class files is not supported. If you need such a component for your tests, we recommend to put this into an extra fixture file. + +::: + ### Spec Page Options The `newSpecPage(options)` method takes an options argument to help write tests: diff --git a/docs/testing/stencil-testrunner/05-e2e-testing.md b/docs/testing/stencil-testrunner/05-e2e-testing.md index 64280629a..c19a8aa20 100644 --- a/docs/testing/stencil-testrunner/05-e2e-testing.md +++ b/docs/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,16 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) +- `logFailingNetworkRequests`: If set to `true`, Stencil will log failing network requests (default: `false`) + ## Example End-to-end Test ```typescript @@ -225,6 +236,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/docs/testing/stencil-testrunner/_category_.json b/docs/testing/stencil-testrunner/_category_.json index 08ddc1c23..30ee95d5f 100644 --- a/docs/testing/stencil-testrunner/_category_.json +++ b/docs/testing/stencil-testrunner/_category_.json @@ -1,4 +1,4 @@ { "label": "Stencil Test Runner", - "position": 9 + "position": 1 } diff --git a/docs/testing/webdriverio/_category_.json b/docs/testing/webdriverio/_category_.json index 3aec28209..dfa20f841 100644 --- a/docs/testing/webdriverio/_category_.json +++ b/docs/testing/webdriverio/_category_.json @@ -1,3 +1,4 @@ { - "label": "WebdriverIO" + "label": "WebdriverIO", + "position": 2 } diff --git a/docusaurus.config.js b/docusaurus.config.js index 87ec55132..274471099 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -72,6 +72,12 @@ const config = { themeConfig: /** @type {import('@ionic-docs/preset-classic').ThemeConfig} */ ({ + announcementBar: { + id: 'announcement-bar', + content: + 'An OutSystems Company →', + isCloseable: false, + }, logo: { alt: 'Site Logo', src: `/img/logo-light.png`, diff --git a/package-lock.json b/package-lock.json index 2a80d2df2..7bba908b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,9 @@ "name": "@stencil/stencil-site", "version": "0.0.0", "dependencies": { - "@docusaurus/core": "^3.1.1", - "@docusaurus/remark-plugin-npm2yarn": "^3.1.1", - "@ionic-docs/preset-classic": "^1.1.0", + "@docusaurus/core": "^3.4.0", + "@docusaurus/remark-plugin-npm2yarn": "^3.4.0", + "@ionic-docs/preset-classic": "^1.2.7", "clsx": "^2.0.0", "docusaurus-theme-github-codeblock": "^2.0.2", "prism-react-renderer": "^2.3.0", @@ -18,7 +18,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "^3.1.1", + "@docusaurus/module-type-aliases": "^3.4.0", "@ionic/prettier-config": "^4.0.0", "cspell": "^8.0.0", "prettier": "^3.2.2", @@ -68,74 +68,74 @@ } }, "node_modules/@algolia/cache-browser-local-storage": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.22.1.tgz", - "integrity": "sha512-Sw6IAmOCvvP6QNgY9j+Hv09mvkvEIDKjYW8ow0UDDAxSXy664RBNQk3i/0nt7gvceOJ6jGmOTimaZoY1THmU7g==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.23.3.tgz", + "integrity": "sha512-vRHXYCpPlTDE7i6UOy2xE03zHF2C8MEFjPN2v7fRbqVpcOvAUQK81x3Kc21xyb5aSIpYCjWCZbYZuz8Glyzyyg==", "dependencies": { - "@algolia/cache-common": "4.22.1" + "@algolia/cache-common": "4.23.3" } }, "node_modules/@algolia/cache-common": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/cache-common/-/cache-common-4.22.1.tgz", - "integrity": "sha512-TJMBKqZNKYB9TptRRjSUtevJeQVXRmg6rk9qgFKWvOy8jhCPdyNZV1nB3SKGufzvTVbomAukFR8guu/8NRKBTA==" + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/cache-common/-/cache-common-4.23.3.tgz", + "integrity": "sha512-h9XcNI6lxYStaw32pHpB1TMm0RuxphF+Ik4o7tcQiodEdpKK+wKufY6QXtba7t3k8eseirEMVB83uFFF3Nu54A==" }, "node_modules/@algolia/cache-in-memory": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/cache-in-memory/-/cache-in-memory-4.22.1.tgz", - "integrity": "sha512-ve+6Ac2LhwpufuWavM/aHjLoNz/Z/sYSgNIXsinGofWOysPilQZPUetqLj8vbvi+DHZZaYSEP9H5SRVXnpsNNw==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/cache-in-memory/-/cache-in-memory-4.23.3.tgz", + "integrity": "sha512-yvpbuUXg/+0rbcagxNT7un0eo3czx2Uf0y4eiR4z4SD7SiptwYTpbuS0IHxcLHG3lq22ukx1T6Kjtk/rT+mqNg==", "dependencies": { - "@algolia/cache-common": "4.22.1" + "@algolia/cache-common": "4.23.3" } }, "node_modules/@algolia/client-account": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/client-account/-/client-account-4.22.1.tgz", - "integrity": "sha512-k8m+oegM2zlns/TwZyi4YgCtyToackkOpE+xCaKCYfBfDtdGOaVZCM5YvGPtK+HGaJMIN/DoTL8asbM3NzHonw==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/client-account/-/client-account-4.23.3.tgz", + "integrity": "sha512-hpa6S5d7iQmretHHF40QGq6hz0anWEHGlULcTIT9tbUssWUriN9AUXIFQ8Ei4w9azD0hc1rUok9/DeQQobhQMA==", "dependencies": { - "@algolia/client-common": "4.22.1", - "@algolia/client-search": "4.22.1", - "@algolia/transporter": "4.22.1" + "@algolia/client-common": "4.23.3", + "@algolia/client-search": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/client-analytics": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/client-analytics/-/client-analytics-4.22.1.tgz", - "integrity": "sha512-1ssi9pyxyQNN4a7Ji9R50nSdISIumMFDwKNuwZipB6TkauJ8J7ha/uO60sPJFqQyqvvI+px7RSNRQT3Zrvzieg==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/client-analytics/-/client-analytics-4.23.3.tgz", + "integrity": "sha512-LBsEARGS9cj8VkTAVEZphjxTjMVCci+zIIiRhpFun9jGDUlS1XmhCW7CTrnaWeIuCQS/2iPyRqSy1nXPjcBLRA==", "dependencies": { - "@algolia/client-common": "4.22.1", - "@algolia/client-search": "4.22.1", - "@algolia/requester-common": "4.22.1", - "@algolia/transporter": "4.22.1" + "@algolia/client-common": "4.23.3", + "@algolia/client-search": "4.23.3", + "@algolia/requester-common": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/client-common": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/client-common/-/client-common-4.22.1.tgz", - "integrity": "sha512-IvaL5v9mZtm4k4QHbBGDmU3wa/mKokmqNBqPj0K7lcR8ZDKzUorhcGp/u8PkPC/e0zoHSTvRh7TRkGX3Lm7iOQ==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/client-common/-/client-common-4.23.3.tgz", + "integrity": "sha512-l6EiPxdAlg8CYhroqS5ybfIczsGUIAC47slLPOMDeKSVXYG1n0qGiz4RjAHLw2aD0xzh2EXZ7aRguPfz7UKDKw==", "dependencies": { - "@algolia/requester-common": "4.22.1", - "@algolia/transporter": "4.22.1" + "@algolia/requester-common": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/client-personalization": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/client-personalization/-/client-personalization-4.22.1.tgz", - "integrity": "sha512-sl+/klQJ93+4yaqZ7ezOttMQ/nczly/3GmgZXJ1xmoewP5jmdP/X/nV5U7EHHH3hCUEHeN7X1nsIhGPVt9E1cQ==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/client-personalization/-/client-personalization-4.23.3.tgz", + "integrity": "sha512-3E3yF3Ocr1tB/xOZiuC3doHQBQ2zu2MPTYZ0d4lpfWads2WTKG7ZzmGnsHmm63RflvDeLK/UVx7j2b3QuwKQ2g==", "dependencies": { - "@algolia/client-common": "4.22.1", - "@algolia/requester-common": "4.22.1", - "@algolia/transporter": "4.22.1" + "@algolia/client-common": "4.23.3", + "@algolia/requester-common": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/client-search": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/client-search/-/client-search-4.22.1.tgz", - "integrity": "sha512-yb05NA4tNaOgx3+rOxAmFztgMTtGBi97X7PC3jyNeGiwkAjOZc2QrdZBYyIdcDLoI09N0gjtpClcackoTN0gPA==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/client-search/-/client-search-4.23.3.tgz", + "integrity": "sha512-P4VAKFHqU0wx9O+q29Q8YVuaowaZ5EM77rxfmGnkHUJggh28useXQdopokgwMeYw2XUht49WX5RcTQ40rZIabw==", "dependencies": { - "@algolia/client-common": "4.22.1", - "@algolia/requester-common": "4.22.1", - "@algolia/transporter": "4.22.1" + "@algolia/client-common": "4.23.3", + "@algolia/requester-common": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/events": { @@ -144,47 +144,65 @@ "integrity": "sha512-FQzvOCgoFXAbf5Y6mYozw2aj5KCJoA3m4heImceldzPSMbdyS4atVjJzXKMsfX3wnZTFYwkkt8/z8UesLHlSBQ==" }, "node_modules/@algolia/logger-common": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/logger-common/-/logger-common-4.22.1.tgz", - "integrity": "sha512-OnTFymd2odHSO39r4DSWRFETkBufnY2iGUZNrMXpIhF5cmFE8pGoINNPzwg02QLBlGSaLqdKy0bM8S0GyqPLBg==" + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/logger-common/-/logger-common-4.23.3.tgz", + "integrity": "sha512-y9kBtmJwiZ9ZZ+1Ek66P0M68mHQzKRxkW5kAAXYN/rdzgDN0d2COsViEFufxJ0pb45K4FRcfC7+33YB4BLrZ+g==" }, "node_modules/@algolia/logger-console": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/logger-console/-/logger-console-4.22.1.tgz", - "integrity": "sha512-O99rcqpVPKN1RlpgD6H3khUWylU24OXlzkavUAMy6QZd1776QAcauE3oP8CmD43nbaTjBexZj2nGsBH9Tc0FVA==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/logger-console/-/logger-console-4.23.3.tgz", + "integrity": "sha512-8xoiseoWDKuCVnWP8jHthgaeobDLolh00KJAdMe9XPrWPuf1by732jSpgy2BlsLTaT9m32pHI8CRfrOqQzHv3A==", "dependencies": { - "@algolia/logger-common": "4.22.1" + "@algolia/logger-common": "4.23.3" + } + }, + "node_modules/@algolia/recommend": { + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/recommend/-/recommend-4.23.3.tgz", + "integrity": "sha512-9fK4nXZF0bFkdcLBRDexsnGzVmu4TSYZqxdpgBW2tEyfuSSY54D4qSRkLmNkrrz4YFvdh2GM1gA8vSsnZPR73w==", + "dependencies": { + "@algolia/cache-browser-local-storage": "4.23.3", + "@algolia/cache-common": "4.23.3", + "@algolia/cache-in-memory": "4.23.3", + "@algolia/client-common": "4.23.3", + "@algolia/client-search": "4.23.3", + "@algolia/logger-common": "4.23.3", + "@algolia/logger-console": "4.23.3", + "@algolia/requester-browser-xhr": "4.23.3", + "@algolia/requester-common": "4.23.3", + "@algolia/requester-node-http": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/@algolia/requester-browser-xhr": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.22.1.tgz", - "integrity": "sha512-dtQGYIg6MteqT1Uay3J/0NDqD+UciHy3QgRbk7bNddOJu+p3hzjTRYESqEnoX/DpEkaNYdRHUKNylsqMpgwaEw==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.23.3.tgz", + "integrity": "sha512-jDWGIQ96BhXbmONAQsasIpTYWslyjkiGu0Quydjlowe+ciqySpiDUrJHERIRfELE5+wFc7hc1Q5hqjGoV7yghw==", "dependencies": { - "@algolia/requester-common": "4.22.1" + "@algolia/requester-common": "4.23.3" } }, "node_modules/@algolia/requester-common": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/requester-common/-/requester-common-4.22.1.tgz", - "integrity": "sha512-dgvhSAtg2MJnR+BxrIFqlLtkLlVVhas9HgYKMk2Uxiy5m6/8HZBL40JVAMb2LovoPFs9I/EWIoFVjOrFwzn5Qg==" + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/requester-common/-/requester-common-4.23.3.tgz", + "integrity": "sha512-xloIdr/bedtYEGcXCiF2muajyvRhwop4cMZo+K2qzNht0CMzlRkm8YsDdj5IaBhshqfgmBb3rTg4sL4/PpvLYw==" }, "node_modules/@algolia/requester-node-http": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/requester-node-http/-/requester-node-http-4.22.1.tgz", - "integrity": "sha512-JfmZ3MVFQkAU+zug8H3s8rZ6h0ahHZL/SpMaSasTCGYR5EEJsCc8SI5UZ6raPN2tjxa5bxS13BRpGSBUens7EA==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/requester-node-http/-/requester-node-http-4.23.3.tgz", + "integrity": "sha512-zgu++8Uj03IWDEJM3fuNl34s746JnZOWn1Uz5taV1dFyJhVM/kTNw9Ik7YJWiUNHJQXcaD8IXD1eCb0nq/aByA==", "dependencies": { - "@algolia/requester-common": "4.22.1" + "@algolia/requester-common": "4.23.3" } }, "node_modules/@algolia/transporter": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@algolia/transporter/-/transporter-4.22.1.tgz", - "integrity": "sha512-kzWgc2c9IdxMa3YqA6TN0NW5VrKYYW/BELIn7vnLyn+U/RFdZ4lxxt9/8yq3DKV5snvoDzzO4ClyejZRdV3lMQ==", + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/@algolia/transporter/-/transporter-4.23.3.tgz", + "integrity": "sha512-Wjl5gttqnf/gQKJA+dafnD0Y6Yw97yvfY8R9h0dQltX1GXTgNs1zWgvtWW0tHl1EgMdhAyw189uWiZMnL3QebQ==", "dependencies": { - "@algolia/cache-common": "4.22.1", - "@algolia/logger-common": "4.22.1", - "@algolia/requester-common": "4.22.1" + "@algolia/cache-common": "4.23.3", + "@algolia/logger-common": "4.23.3", + "@algolia/requester-common": "4.23.3" } }, "node_modules/@ampproject/remapping": { @@ -531,9 +549,9 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", - "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==", + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.6.tgz", + "integrity": "sha512-MZG/JcWfxybKwsA9N9PmtF2lOSFSEMVCpIRrbxccZFLJPrJciJdG/UhSh5W96GEteJI2ARqm5UAHxISwRDLSNg==", "engines": { "node": ">=6.9.0" } @@ -1609,11 +1627,11 @@ } }, "node_modules/@babel/plugin-transform-react-constant-elements": { - "version": "7.23.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-constant-elements/-/plugin-transform-react-constant-elements-7.23.3.tgz", - "integrity": "sha512-zP0QKq/p6O42OL94udMgSfKXyse4RyJ0JqbQ34zDAONWjyrEsghYEyTSK5FIpmXmCpB55SHokL1cRRKHv8L2Qw==", + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-constant-elements/-/plugin-transform-react-constant-elements-7.24.6.tgz", + "integrity": "sha512-vQfyXRtG/kNIcTYRd/49uJnwvMig9X3R4XsTVXRml2RFupZFY+2RDuK+/ymb+MfX2WuIHAgUZc2xEvQrnI7QCg==", "dependencies": { - "@babel/helper-plugin-utils": "^7.22.5" + "@babel/helper-plugin-utils": "^7.24.6" }, "engines": { "node": ">=6.9.0" @@ -2121,61 +2139,63 @@ } }, "node_modules/@cspell/cspell-bundled-dicts": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-8.7.0.tgz", - "integrity": "sha512-B5YQI7Dd9m0JHTmHgs7PiyP4BWXzl8ixpK+HGOwhxzh7GyfFt1Eo/gxMxBDX/9SaewEzeb2OjRpRKEFtEsto3A==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-8.10.4.tgz", + "integrity": "sha512-QmgvIp9/NM60Jj6ft5oaiCFidwPwKYS9FfpfABrDLw/Jx6wwcTdy9cVbuPxT8n4LwkHpswkmIzOf4zSlnrd4MQ==", "dev": true, + "license": "MIT", "dependencies": { "@cspell/dict-ada": "^4.0.2", - "@cspell/dict-aws": "^4.0.1", + "@cspell/dict-aws": "^4.0.2", "@cspell/dict-bash": "^4.1.3", - "@cspell/dict-companies": "^3.0.31", - "@cspell/dict-cpp": "^5.1.3", + "@cspell/dict-companies": "^3.1.2", + "@cspell/dict-cpp": "^5.1.10", "@cspell/dict-cryptocurrencies": "^5.0.0", "@cspell/dict-csharp": "^4.0.2", "@cspell/dict-css": "^4.0.12", "@cspell/dict-dart": "^2.0.3", "@cspell/dict-django": "^4.1.0", "@cspell/dict-docker": "^1.1.7", - "@cspell/dict-dotnet": "^5.0.0", + "@cspell/dict-dotnet": "^5.0.2", "@cspell/dict-elixir": "^4.0.3", - "@cspell/dict-en_us": "^4.3.17", - "@cspell/dict-en-common-misspellings": "^2.0.0", + "@cspell/dict-en_us": "^4.3.23", + "@cspell/dict-en-common-misspellings": "^2.0.3", "@cspell/dict-en-gb": "1.1.33", - "@cspell/dict-filetypes": "^3.0.3", + "@cspell/dict-filetypes": "^3.0.4", "@cspell/dict-fonts": "^4.0.0", "@cspell/dict-fsharp": "^1.0.1", - "@cspell/dict-fullstack": "^3.1.5", + "@cspell/dict-fullstack": "^3.1.8", "@cspell/dict-gaming-terms": "^1.0.5", "@cspell/dict-git": "^3.0.0", - "@cspell/dict-golang": "^6.0.5", + "@cspell/dict-golang": "^6.0.9", + "@cspell/dict-google": "^1.0.1", "@cspell/dict-haskell": "^4.0.1", "@cspell/dict-html": "^4.0.5", "@cspell/dict-html-symbol-entities": "^4.0.0", - "@cspell/dict-java": "^5.0.6", + "@cspell/dict-java": "^5.0.7", "@cspell/dict-julia": "^1.0.1", - "@cspell/dict-k8s": "^1.0.2", + "@cspell/dict-k8s": "^1.0.5", "@cspell/dict-latex": "^4.0.0", "@cspell/dict-lorem-ipsum": "^4.0.0", "@cspell/dict-lua": "^4.0.3", "@cspell/dict-makefile": "^1.0.0", "@cspell/dict-monkeyc": "^1.0.6", - "@cspell/dict-node": "^4.0.3", - "@cspell/dict-npm": "^5.0.15", - "@cspell/dict-php": "^4.0.6", - "@cspell/dict-powershell": "^5.0.3", - "@cspell/dict-public-licenses": "^2.0.6", - "@cspell/dict-python": "^4.1.11", + "@cspell/dict-node": "^5.0.1", + "@cspell/dict-npm": "^5.0.16", + "@cspell/dict-php": "^4.0.8", + "@cspell/dict-powershell": "^5.0.4", + "@cspell/dict-public-licenses": "^2.0.7", + "@cspell/dict-python": "^4.2.1", "@cspell/dict-r": "^2.0.1", "@cspell/dict-ruby": "^5.0.2", - "@cspell/dict-rust": "^4.0.2", - "@cspell/dict-scala": "^5.0.0", - "@cspell/dict-software-terms": "^3.3.18", + "@cspell/dict-rust": "^4.0.4", + "@cspell/dict-scala": "^5.0.2", + "@cspell/dict-software-terms": "^3.4.9", "@cspell/dict-sql": "^2.1.3", "@cspell/dict-svelte": "^1.0.2", "@cspell/dict-swift": "^2.0.1", "@cspell/dict-terraform": "^1.0.0", - "@cspell/dict-typescript": "^3.1.2", + "@cspell/dict-typescript": "^3.1.5", "@cspell/dict-vue": "^3.0.0" }, "engines": { @@ -2183,31 +2203,34 @@ } }, "node_modules/@cspell/cspell-json-reporter": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-json-reporter/-/cspell-json-reporter-8.7.0.tgz", - "integrity": "sha512-LTQPEvXvCqnc+ok9WXpSISZyt4/nGse9fVEM430g0BpGzKpt3RMx49B8uasvvnanzCuikaW9+wFLmwgvraERhA==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-json-reporter/-/cspell-json-reporter-8.10.4.tgz", + "integrity": "sha512-W6aUZ2LkKkDEKgx1sjik2xQT7m6CrLxcuJiF7MkPPZMdsnXyg5jsRalkQTn7my7RZ+n5xxEO69r6jM4IImvWAg==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-types": "8.7.0" + "@cspell/cspell-types": "8.10.4" }, "engines": { "node": ">=18" } }, "node_modules/@cspell/cspell-pipe": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-8.7.0.tgz", - "integrity": "sha512-ePqddIQ4arqPQgOkC146SkZxvZb9/jL7xIM5Igy2n3tiWTC5ijrX/mbHpPZ1VGcFck+1M0cJUuyhuJk+vMj3rg==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-8.10.4.tgz", + "integrity": "sha512-yN+A9EIgdSkNiQnrFgsy5dzFl879ddMRHw/u38Zw4HdHIGr+xLpw5UVSKK6OacPMro853engM3dTJJDzRzh+rA==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } }, "node_modules/@cspell/cspell-resolver": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-8.7.0.tgz", - "integrity": "sha512-grZwDFYqcBYQDaz4AkUtdyqc4UUH2J3/7yWVkBbYDPE+FQHa9ofFXzXxyjs56GJlPfi9ULpe5/Wz6uVLg8rQkQ==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-8.10.4.tgz", + "integrity": "sha512-f0Y+Tol1aqrj9LsDT1oQOoj0P9uJ0ZW5PbhVlKqFeIDhrA5rYLy0ffnFESLNBRxWXaB/cznzpgMUyNfpVCXJpg==", "dev": true, + "license": "MIT", "dependencies": { "global-directory": "^4.0.1" }, @@ -2216,19 +2239,21 @@ } }, "node_modules/@cspell/cspell-service-bus": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-8.7.0.tgz", - "integrity": "sha512-KW48iu0nTDzbedixc7iB7K7mlAZQ7QeMLuM/akxigOlvtOdVJrRa9Pfn44lwejts1ANb/IXil3GH8YylkVi76Q==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-8.10.4.tgz", + "integrity": "sha512-bXIllG6C1rKjWGlKdrAfs0AKrs/iQ6ZL6kSXrzHh5NB8oyBzX8tf5v4BX3Bnh5yrjBzkT2qhL+teEcvWjjvu2w==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } }, "node_modules/@cspell/cspell-types": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-8.7.0.tgz", - "integrity": "sha512-Rb+LCE5I9JEb/LE8nSViVSF8z1CWv/z4mPBIG37VMa7aUx2gAQa6gJekNfpY9YZiMzx4Tv3gDujN80ytks4pGA==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-8.10.4.tgz", + "integrity": "sha512-K/7JALR417KYHoovk18LTJCnKXF8ToNraWX4P3NFkYZNffc62fPn0y7nV9kphdK/biLM7np9gWtHq22MhX4qgw==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } @@ -2237,338 +2262,409 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/@cspell/dict-ada/-/dict-ada-4.0.2.tgz", "integrity": "sha512-0kENOWQeHjUlfyId/aCM/mKXtkEgV0Zu2RhUXCBr4hHo9F9vph+Uu8Ww2b0i5a4ZixoIkudGA+eJvyxrG1jUpA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-aws": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@cspell/dict-aws/-/dict-aws-4.0.1.tgz", - "integrity": "sha512-NXO+kTPQGqaaJKa4kO92NAXoqS+i99dQzf3/L1BxxWVSBS3/k1f3uhmqIh7Crb/n22W793lOm0D9x952BFga3Q==", - "dev": true + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@cspell/dict-aws/-/dict-aws-4.0.3.tgz", + "integrity": "sha512-0C0RQ4EM29fH0tIYv+EgDQEum0QI6OrmjENC9u98pB8UcnYxGG/SqinuPxo+TgcEuInj0Q73MsBpJ1l5xUnrsw==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-bash": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/@cspell/dict-bash/-/dict-bash-4.1.3.tgz", "integrity": "sha512-tOdI3QVJDbQSwPjUkOiQFhYcu2eedmX/PtEpVWg0aFps/r6AyjUQINtTgpqMYnYuq8O1QUIQqnpx21aovcgZCw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-companies": { - "version": "3.0.31", - "resolved": "https://registry.npmjs.org/@cspell/dict-companies/-/dict-companies-3.0.31.tgz", - "integrity": "sha512-hKVpV/lcGKP4/DpEPS8P4osPvFH/YVLJaDn9cBIOH6/HSmL5LbFgJNKpMGaYRbhm2FEX56MKE3yn/MNeNYuesQ==", - "dev": true + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@cspell/dict-companies/-/dict-companies-3.1.2.tgz", + "integrity": "sha512-OwR5i1xbYuJX7FtHQySmTy3iJtPV1rZQ3jFCxFGwrA1xRQ4rtRcDQ+sTXBCIAoJHkXa84f9J3zsngOKmMGyS/w==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-cpp": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/@cspell/dict-cpp/-/dict-cpp-5.1.3.tgz", - "integrity": "sha512-sqnriXRAInZH9W75C+APBh6dtben9filPqVbIsiRMUXGg+s02ekz0z6LbS7kXeJ5mD2qXoMLBrv13qH2eIwutQ==", - "dev": true + "version": "5.1.10", + "resolved": "https://registry.npmjs.org/@cspell/dict-cpp/-/dict-cpp-5.1.10.tgz", + "integrity": "sha512-BmIF0sAz2BgGEOwzYIeEm9ALneDjd1tcTbFbo+A1Hcq3zOKP8yViSgxS9CEN30KOZIyph6Tldp531UPEpoEl0Q==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-cryptocurrencies": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-cryptocurrencies/-/dict-cryptocurrencies-5.0.0.tgz", "integrity": "sha512-Z4ARIw5+bvmShL+4ZrhDzGhnc9znaAGHOEMaB/GURdS/jdoreEDY34wdN0NtdLHDO5KO7GduZnZyqGdRoiSmYA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-csharp": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/@cspell/dict-csharp/-/dict-csharp-4.0.2.tgz", "integrity": "sha512-1JMofhLK+4p4KairF75D3A924m5ERMgd1GvzhwK2geuYgd2ZKuGW72gvXpIV7aGf52E3Uu1kDXxxGAiZ5uVG7g==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-css": { "version": "4.0.12", "resolved": "https://registry.npmjs.org/@cspell/dict-css/-/dict-css-4.0.12.tgz", "integrity": "sha512-vGBgPM92MkHQF5/2jsWcnaahOZ+C6OE/fPvd5ScBP72oFY9tn5GLuomcyO0z8vWCr2e0nUSX1OGimPtcQAlvSw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-dart": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@cspell/dict-dart/-/dict-dart-2.0.3.tgz", "integrity": "sha512-cLkwo1KT5CJY5N5RJVHks2genFkNCl/WLfj+0fFjqNR+tk3tBI1LY7ldr9piCtSFSm4x9pO1x6IV3kRUY1lLiw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-data-science": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@cspell/dict-data-science/-/dict-data-science-1.0.11.tgz", - "integrity": "sha512-TaHAZRVe0Zlcc3C23StZqqbzC0NrodRwoSAc8dis+5qLeLLnOCtagYQeROQvDlcDg3X/VVEO9Whh4W/z4PAmYQ==", - "dev": true + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@cspell/dict-data-science/-/dict-data-science-2.0.1.tgz", + "integrity": "sha512-xeutkzK0eBe+LFXOFU2kJeAYO6IuFUc1g7iRLr7HeCmlC4rsdGclwGHh61KmttL3+YHQytYStxaRBdGAXWC8Lw==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-django": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@cspell/dict-django/-/dict-django-4.1.0.tgz", "integrity": "sha512-bKJ4gPyrf+1c78Z0Oc4trEB9MuhcB+Yg+uTTWsvhY6O2ncFYbB/LbEZfqhfmmuK/XJJixXfI1laF2zicyf+l0w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-docker": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@cspell/dict-docker/-/dict-docker-1.1.7.tgz", "integrity": "sha512-XlXHAr822euV36GGsl2J1CkBIVg3fZ6879ZOg5dxTIssuhUOCiV2BuzKZmt6aIFmcdPmR14+9i9Xq+3zuxeX0A==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-dotnet": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@cspell/dict-dotnet/-/dict-dotnet-5.0.0.tgz", - "integrity": "sha512-EOwGd533v47aP5QYV8GlSSKkmM9Eq8P3G/eBzSpH3Nl2+IneDOYOBLEUraHuiCtnOkNsz0xtZHArYhAB2bHWAw==", - "dev": true + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@cspell/dict-dotnet/-/dict-dotnet-5.0.2.tgz", + "integrity": "sha512-UD/pO2A2zia/YZJ8Kck/F6YyDSpCMq0YvItpd4YbtDVzPREfTZ48FjZsbYi4Jhzwfvc6o8R56JusAE58P+4sNQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-elixir": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@cspell/dict-elixir/-/dict-elixir-4.0.3.tgz", "integrity": "sha512-g+uKLWvOp9IEZvrIvBPTr/oaO6619uH/wyqypqvwpmnmpjcfi8+/hqZH8YNKt15oviK8k4CkINIqNhyndG9d9Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-en_us": { - "version": "4.3.18", - "resolved": "https://registry.npmjs.org/@cspell/dict-en_us/-/dict-en_us-4.3.18.tgz", - "integrity": "sha512-D8jGT7Zi3+e8zIpT0NqGKvvzehcvUETFlOA0NxcRStkw7H7mgouHxKFU+u7t3tvCoGNwh2gwjCqZQlK8ZXwQHw==", - "dev": true + "version": "4.3.23", + "resolved": "https://registry.npmjs.org/@cspell/dict-en_us/-/dict-en_us-4.3.23.tgz", + "integrity": "sha512-l0SoEQBsi3zDSl3OuL4/apBkxjuj4hLIg/oy6+gZ7LWh03rKdF6VNtSZNXWAmMY+pmb1cGA3ouleTiJIglbsIg==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-en-common-misspellings": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@cspell/dict-en-common-misspellings/-/dict-en-common-misspellings-2.0.0.tgz", - "integrity": "sha512-NOg8dlv37/YqLkCfBs5OXeJm/Wcfb/CzeOmOZJ2ZXRuxwsNuolb4TREUce0yAXRqMhawahY5TSDRJJBgKjBOdw==", - "dev": true + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@cspell/dict-en-common-misspellings/-/dict-en-common-misspellings-2.0.3.tgz", + "integrity": "sha512-8nF1z9nUiSgMyikL66HTbDO7jCGtB24TxKBasXIBwkBKMDZgA2M883iXdeByy6m1JJUcCGFkSftVYp2W0bUgjw==", + "dev": true, + "license": "CC BY-SA 4.0" }, "node_modules/@cspell/dict-en-gb": { "version": "1.1.33", "resolved": "https://registry.npmjs.org/@cspell/dict-en-gb/-/dict-en-gb-1.1.33.tgz", "integrity": "sha512-tKSSUf9BJEV+GJQAYGw5e+ouhEe2ZXE620S7BLKe3ZmpnjlNG9JqlnaBhkIMxKnNFkLY2BP/EARzw31AZnOv4g==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-filetypes": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@cspell/dict-filetypes/-/dict-filetypes-3.0.3.tgz", - "integrity": "sha512-J9UP+qwwBLfOQ8Qg9tAsKtSY/WWmjj21uj6zXTI9hRLD1eG1uUOLcfVovAmtmVqUWziPSKMr87F6SXI3xmJXgw==", - "dev": true + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@cspell/dict-filetypes/-/dict-filetypes-3.0.4.tgz", + "integrity": "sha512-IBi8eIVdykoGgIv5wQhOURi5lmCNJq0we6DvqKoPQJHthXbgsuO1qrHSiUVydMiQl/XvcnUWTMeAlVUlUClnVg==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-fonts": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-fonts/-/dict-fonts-4.0.0.tgz", "integrity": "sha512-t9V4GeN/m517UZn63kZPUYP3OQg5f0OBLSd3Md5CU3eH1IFogSvTzHHnz4Wqqbv8NNRiBZ3HfdY/pqREZ6br3Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-fsharp": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@cspell/dict-fsharp/-/dict-fsharp-1.0.1.tgz", "integrity": "sha512-23xyPcD+j+NnqOjRHgW3IU7Li912SX9wmeefcY0QxukbAxJ/vAN4rBpjSwwYZeQPAn3fxdfdNZs03fg+UM+4yQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-fullstack": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/@cspell/dict-fullstack/-/dict-fullstack-3.1.5.tgz", - "integrity": "sha512-6ppvo1dkXUZ3fbYn/wwzERxCa76RtDDl5Afzv2lijLoijGGUw5yYdLBKJnx8PJBGNLh829X352ftE7BElG4leA==", - "dev": true + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/@cspell/dict-fullstack/-/dict-fullstack-3.1.8.tgz", + "integrity": "sha512-YRlZupL7uqMCtEBK0bDP9BrcPnjDhz7m4GBqCc1EYqfXauHbLmDT8ELha7T/E7wsFKniHSjzwDZzhNXo2lusRQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-gaming-terms": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@cspell/dict-gaming-terms/-/dict-gaming-terms-1.0.5.tgz", "integrity": "sha512-C3riccZDD3d9caJQQs1+MPfrUrQ+0KHdlj9iUR1QD92FgTOF6UxoBpvHUUZ9YSezslcmpFQK4xQQ5FUGS7uWfw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-git": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-git/-/dict-git-3.0.0.tgz", "integrity": "sha512-simGS/lIiXbEaqJu9E2VPoYW1OTC2xrwPPXNXFMa2uo/50av56qOuaxDrZ5eH1LidFXwoc8HROCHYeKoNrDLSw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-golang": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/@cspell/dict-golang/-/dict-golang-6.0.5.tgz", - "integrity": "sha512-w4mEqGz4/wV+BBljLxduFNkMrd3rstBNDXmoX5kD4UTzIb4Sy0QybWCtg2iVT+R0KWiRRA56QKOvBsgXiddksA==", - "dev": true + "version": "6.0.9", + "resolved": "https://registry.npmjs.org/@cspell/dict-golang/-/dict-golang-6.0.9.tgz", + "integrity": "sha512-etDt2WQauyEQDA+qPS5QtkYTb2I9l5IfQftAllVoB1aOrT6bxxpHvMEpJ0Hsn/vezxrCqa/BmtUbRxllIxIuSg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@cspell/dict-google": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@cspell/dict-google/-/dict-google-1.0.1.tgz", + "integrity": "sha512-dQr4M3n95uOhtloNSgB9tYYGXGGEGEykkFyRtfcp5pFuEecYUa0BSgtlGKx9RXVtJtKgR+yFT/a5uQSlt8WjqQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-haskell": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@cspell/dict-haskell/-/dict-haskell-4.0.1.tgz", "integrity": "sha512-uRrl65mGrOmwT7NxspB4xKXFUenNC7IikmpRZW8Uzqbqcu7ZRCUfstuVH7T1rmjRgRkjcIjE4PC11luDou4wEQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-html": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@cspell/dict-html/-/dict-html-4.0.5.tgz", "integrity": "sha512-p0brEnRybzSSWi8sGbuVEf7jSTDmXPx7XhQUb5bgG6b54uj+Z0Qf0V2n8b/LWwIPJNd1GygaO9l8k3HTCy1h4w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-html-symbol-entities": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-html-symbol-entities/-/dict-html-symbol-entities-4.0.0.tgz", "integrity": "sha512-HGRu+48ErJjoweR5IbcixxETRewrBb0uxQBd6xFGcxbEYCX8CnQFTAmKI5xNaIt2PKaZiJH3ijodGSqbKdsxhw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-java": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/@cspell/dict-java/-/dict-java-5.0.6.tgz", - "integrity": "sha512-kdE4AHHHrixyZ5p6zyms1SLoYpaJarPxrz8Tveo6gddszBVVwIUZ+JkQE1bWNLK740GWzIXdkznpUfw1hP9nXw==", - "dev": true + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/@cspell/dict-java/-/dict-java-5.0.7.tgz", + "integrity": "sha512-ejQ9iJXYIq7R09BScU2y5OUGrSqwcD+J5mHFOKbduuQ5s/Eh/duz45KOzykeMLI6KHPVxhBKpUPBWIsfewECpQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-julia": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@cspell/dict-julia/-/dict-julia-1.0.1.tgz", "integrity": "sha512-4JsCLCRhhLMLiaHpmR7zHFjj1qOauzDI5ZzCNQS31TUMfsOo26jAKDfo0jljFAKgw5M2fEG7sKr8IlPpQAYrmQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-k8s": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@cspell/dict-k8s/-/dict-k8s-1.0.2.tgz", - "integrity": "sha512-tLT7gZpNPnGa+IIFvK9SP1LrSpPpJ94a/DulzAPOb1Q2UBFwdpFd82UWhio0RNShduvKG/WiMZf/wGl98pn+VQ==", - "dev": true + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@cspell/dict-k8s/-/dict-k8s-1.0.5.tgz", + "integrity": "sha512-Cj+/ZV4S+MKlwfocSJZqe/2UAd/sY8YtlZjbK25VN1nCnrsKrBjfkX29vclwSj1U9aJg4Z9jw/uMjoaKu9ZrpQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-latex": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-latex/-/dict-latex-4.0.0.tgz", "integrity": "sha512-LPY4y6D5oI7D3d+5JMJHK/wxYTQa2lJMSNxps2JtuF8hbAnBQb3igoWEjEbIbRRH1XBM0X8dQqemnjQNCiAtxQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-lorem-ipsum": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-lorem-ipsum/-/dict-lorem-ipsum-4.0.0.tgz", "integrity": "sha512-1l3yjfNvMzZPibW8A7mQU4kTozwVZVw0AvFEdy+NcqtbxH+TvbSkNMqROOFWrkD2PjnKG0+Ea0tHI2Pi6Gchnw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-lua": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@cspell/dict-lua/-/dict-lua-4.0.3.tgz", "integrity": "sha512-lDHKjsrrbqPaea13+G9s0rtXjMO06gPXPYRjRYawbNmo4E/e3XFfVzeci3OQDQNDmf2cPOwt9Ef5lu2lDmwfJg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-makefile": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-makefile/-/dict-makefile-1.0.0.tgz", "integrity": "sha512-3W9tHPcSbJa6s0bcqWo6VisEDTSN5zOtDbnPabF7rbyjRpNo0uHXHRJQF8gAbFzoTzBBhgkTmrfSiuyQm7vBUQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-monkeyc": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@cspell/dict-monkeyc/-/dict-monkeyc-1.0.6.tgz", "integrity": "sha512-oO8ZDu/FtZ55aq9Mb67HtaCnsLn59xvhO/t2mLLTHAp667hJFxpp7bCtr2zOrR1NELzFXmKln/2lw/PvxMSvrA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-node": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/@cspell/dict-node/-/dict-node-4.0.3.tgz", - "integrity": "sha512-sFlUNI5kOogy49KtPg8SMQYirDGIAoKBO3+cDLIwD4MLdsWy1q0upc7pzGht3mrjuyMiPRUV14Bb0rkVLrxOhg==", - "dev": true + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@cspell/dict-node/-/dict-node-5.0.1.tgz", + "integrity": "sha512-lax/jGz9h3Dv83v8LHa5G0bf6wm8YVRMzbjJPG/9rp7cAGPtdrga+XANFq+B7bY5+jiSA3zvj10LUFCFjnnCCg==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-npm": { - "version": "5.0.15", - "resolved": "https://registry.npmjs.org/@cspell/dict-npm/-/dict-npm-5.0.15.tgz", - "integrity": "sha512-sX0X5YWNW54F4baW7b5JJB6705OCBIZtUqjOghlJNORS5No7QY1IX1zc5FxNNu4gsaCZITAmfMi4ityXEsEThA==", - "dev": true + "version": "5.0.16", + "resolved": "https://registry.npmjs.org/@cspell/dict-npm/-/dict-npm-5.0.16.tgz", + "integrity": "sha512-ZWPnLAziEcSCvV0c8k9Qj88pfMu+wZwM5Qks87ShsfBgI8uLZ9tGHravA7gmjH1Gd7Bgxy2ulvXtSqIWPh1lew==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-php": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/@cspell/dict-php/-/dict-php-4.0.6.tgz", - "integrity": "sha512-ySAXisf7twoVFZqBV2o/DKiCLIDTHNqfnj0EfH9OoOUR7HL3rb6zJkm0viLUFDO2G/8SyIi6YrN/6KX+Scjjjg==", - "dev": true + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/@cspell/dict-php/-/dict-php-4.0.8.tgz", + "integrity": "sha512-TBw3won4MCBQ2wdu7kvgOCR3dY2Tb+LJHgDUpuquy3WnzGiSDJ4AVelrZdE1xu7mjFJUr4q48aB21YT5uQqPZA==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-powershell": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/@cspell/dict-powershell/-/dict-powershell-5.0.3.tgz", - "integrity": "sha512-lEdzrcyau6mgzu1ie98GjOEegwVHvoaWtzQnm1ie4DyZgMr+N6D0Iyj1lzvtmt0snvsDFa5F2bsYzf3IMKcpcA==", - "dev": true + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@cspell/dict-powershell/-/dict-powershell-5.0.4.tgz", + "integrity": "sha512-eosDShapDgBWN9ULF7+sRNdUtzRnUdsfEdBSchDm8FZA4HOqxUSZy3b/cX/Rdw0Fnw0AKgk0kzgXw7tS6vwJMQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-public-licenses": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/@cspell/dict-public-licenses/-/dict-public-licenses-2.0.6.tgz", - "integrity": "sha512-bHqpSpJvLCUcWxj1ov/Ki8WjmESpYwRpQlqfdchekOTc93Huhvjm/RXVN1R4fVf4Hspyem1QVkCGqAmjJMj6sw==", - "dev": true + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@cspell/dict-public-licenses/-/dict-public-licenses-2.0.7.tgz", + "integrity": "sha512-KlBXuGcN3LE7tQi/GEqKiDewWGGuopiAD0zRK1QilOx5Co8XAvs044gk4MNIQftc8r0nHeUI+irJKLGcR36DIQ==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-python": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/@cspell/dict-python/-/dict-python-4.1.11.tgz", - "integrity": "sha512-XG+v3PumfzUW38huSbfT15Vqt3ihNb462ulfXifpQllPok5OWynhszCLCRQjQReV+dgz784ST4ggRxW452/kVg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@cspell/dict-python/-/dict-python-4.2.1.tgz", + "integrity": "sha512-9X2jRgyM0cxBoFQRo4Zc8oacyWnXi+0/bMI5FGibZNZV4y/o9UoFEr6agjU260/cXHTjIdkX233nN7eb7dtyRg==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/dict-data-science": "^1.0.11" + "@cspell/dict-data-science": "^2.0.1" } }, "node_modules/@cspell/dict-r": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@cspell/dict-r/-/dict-r-2.0.1.tgz", "integrity": "sha512-KCmKaeYMLm2Ip79mlYPc8p+B2uzwBp4KMkzeLd5E6jUlCL93Y5Nvq68wV5fRLDRTf7N1LvofkVFWfDcednFOgA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-ruby": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@cspell/dict-ruby/-/dict-ruby-5.0.2.tgz", "integrity": "sha512-cIh8KTjpldzFzKGgrqUX4bFyav5lC52hXDKo4LbRuMVncs3zg4hcSf4HtURY+f2AfEZzN6ZKzXafQpThq3dl2g==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-rust": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@cspell/dict-rust/-/dict-rust-4.0.2.tgz", - "integrity": "sha512-RhziKDrklzOntxAbY3AvNR58wnFGIo3YS8+dNeLY36GFuWOvXDHFStYw5Pod4f/VXbO/+1tXtywCC4zWfB2p1w==", - "dev": true + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@cspell/dict-rust/-/dict-rust-4.0.4.tgz", + "integrity": "sha512-v9/LcZknt/Xq7m1jdTWiQEtmkVVKdE1etAfGL2sgcWpZYewEa459HeWndNA0gfzQrpWX9sYay18mt7pqClJEdA==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-scala": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@cspell/dict-scala/-/dict-scala-5.0.0.tgz", - "integrity": "sha512-ph0twaRoV+ylui022clEO1dZ35QbeEQaKTaV2sPOsdwIokABPIiK09oWwGK9qg7jRGQwVaRPEq0Vp+IG1GpqSQ==", - "dev": true + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@cspell/dict-scala/-/dict-scala-5.0.2.tgz", + "integrity": "sha512-v97ClgidZt99JUm7OjhQugDHmhx4U8fcgunHvD/BsXWjXNj4cTr0m0YjofyZoL44WpICsNuFV9F/sv9OM5HUEw==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-software-terms": { - "version": "3.3.18", - "resolved": "https://registry.npmjs.org/@cspell/dict-software-terms/-/dict-software-terms-3.3.18.tgz", - "integrity": "sha512-LJZGGMGqS8KzgXJrSMs3T+6GoqHG9z8Bc+rqLzLzbtoR3FbsMasE9U8oP2PmS3q7jJLFjQkzmg508DrcuZuo2g==", - "dev": true + "version": "3.4.10", + "resolved": "https://registry.npmjs.org/@cspell/dict-software-terms/-/dict-software-terms-3.4.10.tgz", + "integrity": "sha512-S5S2sz98v4GWJ9TMo62Vp4L5RM/329e5UQfFn7yJfieTcrfXRH4IweVdz34rZcK9o5coGptgBUIv/Jcrd4cMpg==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-sql": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@cspell/dict-sql/-/dict-sql-2.1.3.tgz", "integrity": "sha512-SEyTNKJrjqD6PAzZ9WpdSu6P7wgdNtGV2RV8Kpuw1x6bV+YsSptuClYG+JSdRExBTE6LwIe1bTklejUp3ZP8TQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-svelte": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@cspell/dict-svelte/-/dict-svelte-1.0.2.tgz", "integrity": "sha512-rPJmnn/GsDs0btNvrRBciOhngKV98yZ9SHmg8qI6HLS8hZKvcXc0LMsf9LLuMK1TmS2+WQFAan6qeqg6bBxL2Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-swift": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@cspell/dict-swift/-/dict-swift-2.0.1.tgz", "integrity": "sha512-gxrCMUOndOk7xZFmXNtkCEeroZRnS2VbeaIPiymGRHj5H+qfTAzAKxtv7jJbVA3YYvEzWcVE2oKDP4wcbhIERw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-terraform": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-terraform/-/dict-terraform-1.0.0.tgz", "integrity": "sha512-Ak+vy4HP/bOgzf06BAMC30+ZvL9mzv21xLM2XtfnBLTDJGdxlk/nK0U6QT8VfFLqJ0ZZSpyOxGsUebWDCTr/zQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-typescript": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@cspell/dict-typescript/-/dict-typescript-3.1.3.tgz", - "integrity": "sha512-TdD789OWwOImH/IMyz/QRA6LJz7ScI/qbn1YOkcAW3AROvgbc0oKAxzp08+Xu8tj4GROrJ9UqZdh0t9xQCPkPg==", - "dev": true + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@cspell/dict-typescript/-/dict-typescript-3.1.5.tgz", + "integrity": "sha512-EkIwwNV/xqEoBPJml2S16RXj65h1kvly8dfDLgXerrKw6puybZdvAHerAph6/uPTYdtLcsPyJYkPt5ISOJYrtw==", + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dict-vue": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@cspell/dict-vue/-/dict-vue-3.0.0.tgz", "integrity": "sha512-niiEMPWPV9IeRBRzZ0TBZmNnkK3olkOPYxC1Ny2AX4TGlYRajcW0WUtoSHmvvjZNfWLSg2L6ruiBeuPSbjnG6A==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@cspell/dynamic-import": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-8.7.0.tgz", - "integrity": "sha512-xlEPdiHVDu+4xYkvwjL9MgklxOi9XB+Pr1H9s3Ww9WEq+q6BA3xOHxLIU/k8mhqFTMZGFZRCsdy/EwMu6SyRhQ==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-8.10.4.tgz", + "integrity": "sha512-YxpzOgrP/u0nxEMR4hUfV+4z3b0rLWnKsKIv6pLpRez7ACvrMeb53FedSMZW/YaF3NjWTpUEdqFHaemPkmwnRA==", "dev": true, + "license": "MIT", "dependencies": { - "import-meta-resolve": "^4.0.0" + "import-meta-resolve": "^4.1.0" }, "engines": { "node": ">=18.0" } }, "node_modules/@cspell/strong-weak-map": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-8.7.0.tgz", - "integrity": "sha512-0bo0WwDr2lzGoCP7vbpWbDpPyuOrHKK+218txnUpx6Pn1EDBLfcDQsiZED5B6zlpwgbGi6y3vc0rWtJbjKvwzg==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-8.10.4.tgz", + "integrity": "sha512-QyL8mvv8HDnIHU/wKqWf04yMHCHv3icakZF4UdAk181tl8gymzrtyXSSbMaVlySlK9p+7OQlEG/KUF8R0LR75Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } }, + "node_modules/@cspell/url": { + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/@cspell/url/-/url-8.10.4.tgz", + "integrity": "sha512-4+Bxm43py50W872FjUvKoT9+EQoK9pqOblxu7GRfFx7CjEgYJB03Cb4rHiKYzLuJakUk6IyAlgPD2vNZO37Vzg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.0" + } + }, "node_modules/@csstools/postcss-cascade-layers": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@csstools/postcss-cascade-layers/-/postcss-cascade-layers-2.0.0.tgz", @@ -2612,18 +2708,18 @@ } }, "node_modules/@docsearch/css": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/@docsearch/css/-/css-3.5.2.tgz", - "integrity": "sha512-SPiDHaWKQZpwR2siD0KQUwlStvIAnEyK6tAE2h2Wuoq8ue9skzhlyVQ1ddzOxX6khULnAALDiR/isSF3bnuciA==" + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@docsearch/css/-/css-3.6.0.tgz", + "integrity": "sha512-+sbxb71sWre+PwDK7X2T8+bhS6clcVMLwBPznX45Qu6opJcgRjAp7gYSDzVFp187J+feSj5dNBN1mJoi6ckkUQ==" }, "node_modules/@docsearch/react": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/@docsearch/react/-/react-3.5.2.tgz", - "integrity": "sha512-9Ahcrs5z2jq/DcAvYtvlqEBHImbm4YJI8M9y0x6Tqg598P40HTEkX7hsMcIuThI+hTFxRGZ9hll0Wygm2yEjng==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@docsearch/react/-/react-3.6.0.tgz", + "integrity": "sha512-HUFut4ztcVNmqy9gp/wxNbC7pTOHhgVVkHVGCACTuLhUKUhKAF9KYHJtMiLUJxEqiFLQiuri1fWF8zqwM/cu1w==", "dependencies": { "@algolia/autocomplete-core": "1.9.3", "@algolia/autocomplete-preset-algolia": "1.9.3", - "@docsearch/css": "3.5.2", + "@docsearch/css": "3.6.0", "algoliasearch": "^4.19.1" }, "peerDependencies": { @@ -2648,9 +2744,9 @@ } }, "node_modules/@docusaurus/core": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/core/-/core-3.1.1.tgz", - "integrity": "sha512-2nQfKFcf+MLEM7JXsXwQxPOmQAR6ytKMZVSx7tVi9HEm9WtfwBH1fp6bn8Gj4zLUhjWKCLoysQ9/Wm+EZCQ4yQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/core/-/core-3.4.0.tgz", + "integrity": "sha512-g+0wwmN2UJsBqy2fQRQ6fhXruoEa62JDeEa5d8IdTJlMoaDaEDfHh7WjwGRn4opuTQWpjAwP/fbcgyHKlE+64w==", "dependencies": { "@babel/core": "^7.23.3", "@babel/generator": "^7.23.3", @@ -2662,15 +2758,12 @@ "@babel/runtime": "^7.22.6", "@babel/runtime-corejs3": "^7.22.6", "@babel/traverse": "^7.22.8", - "@docusaurus/cssnano-preset": "3.1.1", - "@docusaurus/logger": "3.1.1", - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/react-loadable": "5.5.2", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-common": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@slorber/static-site-generator-webpack-plugin": "^4.0.7", - "@svgr/webpack": "^6.5.1", + "@docusaurus/cssnano-preset": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "autoprefixer": "^10.4.14", "babel-loader": "^9.1.3", "babel-plugin-dynamic-import-node": "^2.3.3", @@ -2684,12 +2777,13 @@ "copy-webpack-plugin": "^11.0.0", "core-js": "^3.31.1", "css-loader": "^6.8.1", - "css-minimizer-webpack-plugin": "^4.2.2", - "cssnano": "^5.1.15", + "css-minimizer-webpack-plugin": "^5.0.1", + "cssnano": "^6.1.2", "del": "^6.1.1", "detect-port": "^1.5.1", "escape-html": "^1.0.3", "eta": "^2.2.0", + "eval": "^0.1.8", "file-loader": "^6.2.0", "fs-extra": "^11.1.1", "html-minifier-terser": "^7.2.0", @@ -2698,12 +2792,13 @@ "leven": "^3.1.0", "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.7.6", + "p-map": "^4.0.0", "postcss": "^8.4.26", "postcss-loader": "^7.3.3", "prompts": "^2.4.2", "react-dev-utils": "^12.0.1", "react-helmet-async": "^1.3.0", - "react-loadable": "npm:@docusaurus/react-loadable@5.5.2", + "react-loadable": "npm:@docusaurus/react-loadable@6.0.0", "react-loadable-ssr-addon-v5-slorber": "^1.0.1", "react-router": "^5.3.4", "react-router-config": "^5.1.1", @@ -2733,54 +2828,14 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/core/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@mdx-js/mdx": "^3.0.0", - "@slorber/remark-comment": "^1.0.0", - "escape-html": "^1.0.3", - "estree-util-value-to-estree": "^3.0.1", - "file-loader": "^6.2.0", - "fs-extra": "^11.1.1", - "image-size": "^1.0.2", - "mdast-util-mdx": "^3.0.0", - "mdast-util-to-string": "^4.0.0", - "rehype-raw": "^7.0.0", - "remark-directive": "^3.0.0", - "remark-emoji": "^4.0.0", - "remark-frontmatter": "^5.0.0", - "remark-gfm": "^4.0.0", - "stringify-object": "^3.3.0", - "tslib": "^2.6.0", - "unified": "^11.0.3", - "unist-util-visit": "^5.0.0", - "url-loader": "^4.1.1", - "vfile": "^6.0.1", - "webpack": "^5.88.1" - }, - "engines": { - "node": ">=18.0" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, "node_modules/@docusaurus/cssnano-preset": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/cssnano-preset/-/cssnano-preset-3.1.1.tgz", - "integrity": "sha512-LnoIDjJWbirdbVZDMq+4hwmrTl2yHDnBf9MLG9qyExeAE3ac35s4yUhJI8yyTCdixzNfKit4cbXblzzqMu4+8g==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/cssnano-preset/-/cssnano-preset-3.4.0.tgz", + "integrity": "sha512-qwLFSz6v/pZHy/UP32IrprmH5ORce86BGtN0eBtG75PpzQJAzp9gefspox+s8IEOr0oZKuQ/nhzZ3xwyc3jYJQ==", "dependencies": { - "cssnano-preset-advanced": "^5.3.10", - "postcss": "^8.4.26", - "postcss-sort-media-queries": "^4.4.1", + "cssnano-preset-advanced": "^6.1.2", + "postcss": "^8.4.38", + "postcss-sort-media-queries": "^5.2.0", "tslib": "^2.6.0" }, "engines": { @@ -2788,9 +2843,9 @@ } }, "node_modules/@docusaurus/logger": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/logger/-/logger-3.1.1.tgz", - "integrity": "sha512-BjkNDpQzewcTnST8trx4idSoAla6zZ3w22NqM/UMcFtvYJgmoE4layuTzlfql3VFPNuivvj7BOExa/+21y4X2Q==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/logger/-/logger-3.4.0.tgz", + "integrity": "sha512-bZwkX+9SJ8lB9kVRkXw+xvHYSMGG4bpYHKGXeXFvyVc79NMeeBSGgzd4TQLHH+DYeOJoCdl8flrFJVxlZ0wo/Q==", "dependencies": { "chalk": "^4.1.2", "tslib": "^2.6.0" @@ -2800,11 +2855,11 @@ } }, "node_modules/@docusaurus/lqip-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/lqip-loader/-/lqip-loader-3.1.1.tgz", - "integrity": "sha512-s06lySAX5ghCiQe0+/GaMWcVvgkBQ6U8p182fW+JbdjxABS8ecx2in2AQJbvrwKNgiMjOhsXiaE6BmbQAmT6nw==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/lqip-loader/-/lqip-loader-3.4.0.tgz", + "integrity": "sha512-F//Gjqcz925zLL1l3Y3XOtQvn927GBIr9ZouvzWF4jHNKuuHBqzOPSADF5O/cT3Vq1ucPWooyhPBxYcvSGF4SA==", "dependencies": { - "@docusaurus/logger": "3.1.1", + "@docusaurus/logger": "3.4.0", "file-loader": "^6.2.0", "lodash": "^4.17.21", "sharp": "^0.32.3", @@ -2814,66 +2869,14 @@ "node": ">=18.0" } }, - "node_modules/@docusaurus/module-type-aliases": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/module-type-aliases/-/module-type-aliases-3.1.1.tgz", - "integrity": "sha512-xBJyx0TMfAfVZ9ZeIOb1awdXgR4YJMocIEzTps91rq+hJDFJgJaylDtmoRhUxkwuYmNK1GJpW95b7DLztSBJ3A==", + "node_modules/@docusaurus/mdx-loader": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.4.0.tgz", + "integrity": "sha512-kSSbrrk4nTjf4d+wtBA9H+FGauf2gCax89kV8SUSJu3qaTdSIKdWERlngsiHaCFgZ7laTJ8a67UFf+xlFPtuTw==", "dependencies": { - "@docusaurus/react-loadable": "5.5.2", - "@docusaurus/types": "3.1.1", - "@types/history": "^4.7.11", - "@types/react": "*", - "@types/react-router-config": "*", - "@types/react-router-dom": "*", - "react-helmet-async": "*", - "react-loadable": "npm:@docusaurus/react-loadable@5.5.2" - }, - "peerDependencies": { - "react": "*", - "react-dom": "*" - } - }, - "node_modules/@docusaurus/plugin-content-blog": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-3.1.1.tgz", - "integrity": "sha512-ew/3VtVoG3emoAKmoZl7oKe1zdFOsI0NbcHS26kIxt2Z8vcXKCUgK9jJJrz0TbOipyETPhqwq4nbitrY3baibg==", - "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/logger": "3.1.1", - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-common": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "cheerio": "^1.0.0-rc.12", - "feed": "^4.2.2", - "fs-extra": "^11.1.1", - "lodash": "^4.17.21", - "reading-time": "^1.5.0", - "srcset": "^4.0.0", - "tslib": "^2.6.0", - "unist-util-visit": "^5.0.0", - "utility-types": "^3.10.0", - "webpack": "^5.88.1" - }, - "engines": { - "node": ">=18.0" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, - "node_modules/@docusaurus/plugin-content-blog/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "@docusaurus/logger": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "@mdx-js/mdx": "^3.0.0", "@slorber/remark-comment": "^1.0.0", "escape-html": "^1.0.3", @@ -2904,65 +2907,45 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/plugin-content-docs": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-docs/-/plugin-content-docs-3.1.1.tgz", - "integrity": "sha512-lhFq4E874zw0UOH7ujzxnCayOyAt0f9YPVYSb9ohxrdCM8B4szxitUw9rIX4V9JLLHVoqIJb6k+lJJ1jrcGJ0A==", - "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/logger": "3.1.1", - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/module-type-aliases": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@types/react-router-config": "^5.0.7", - "combine-promises": "^1.1.0", - "fs-extra": "^11.1.1", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "tslib": "^2.6.0", - "utility-types": "^3.10.0", - "webpack": "^5.88.1" - }, - "engines": { - "node": ">=18.0" + "node_modules/@docusaurus/module-type-aliases": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/module-type-aliases/-/module-type-aliases-3.4.0.tgz", + "integrity": "sha512-A1AyS8WF5Bkjnb8s+guTDuYmUiwJzNrtchebBHpc0gz0PyHJNMaybUlSrmJjHVcGrya0LKI4YcR3lBDQfXRYLw==", + "dependencies": { + "@docusaurus/types": "3.4.0", + "@types/history": "^4.7.11", + "@types/react": "*", + "@types/react-router-config": "*", + "@types/react-router-dom": "*", + "react-helmet-async": "*", + "react-loadable": "npm:@docusaurus/react-loadable@6.0.0" }, "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" + "react": "*", + "react-dom": "*" } }, - "node_modules/@docusaurus/plugin-content-docs/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@mdx-js/mdx": "^3.0.0", - "@slorber/remark-comment": "^1.0.0", - "escape-html": "^1.0.3", - "estree-util-value-to-estree": "^3.0.1", - "file-loader": "^6.2.0", + "node_modules/@docusaurus/plugin-content-blog": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-blog/-/plugin-content-blog-3.4.0.tgz", + "integrity": "sha512-vv6ZAj78ibR5Jh7XBUT4ndIjmlAxkijM3Sx5MAAzC1gyv0vupDQNhzuFg1USQmQVj3P5I6bquk12etPV3LJ+Xw==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", + "cheerio": "^1.0.0-rc.12", + "feed": "^4.2.2", "fs-extra": "^11.1.1", - "image-size": "^1.0.2", - "mdast-util-mdx": "^3.0.0", - "mdast-util-to-string": "^4.0.0", - "rehype-raw": "^7.0.0", - "remark-directive": "^3.0.0", - "remark-emoji": "^4.0.0", - "remark-frontmatter": "^5.0.0", - "remark-gfm": "^4.0.0", - "stringify-object": "^3.3.0", + "lodash": "^4.17.21", + "reading-time": "^1.5.0", + "srcset": "^4.0.0", "tslib": "^2.6.0", - "unified": "^11.0.3", "unist-util-visit": "^5.0.0", - "url-loader": "^4.1.1", - "vfile": "^6.0.1", + "utility-types": "^3.10.0", "webpack": "^5.88.1" }, "engines": { @@ -2973,18 +2956,26 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/plugin-content-pages": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-pages/-/plugin-content-pages-3.1.1.tgz", - "integrity": "sha512-NQHncNRAJbyLtgTim9GlEnNYsFhuCxaCNkMwikuxLTiGIPH7r/jpb7O3f3jUMYMebZZZrDq5S7om9a6rvB/YCA==", - "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "node_modules/@docusaurus/plugin-content-docs": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-docs/-/plugin-content-docs-3.4.0.tgz", + "integrity": "sha512-HkUCZffhBo7ocYheD9oZvMcDloRnGhBMOZRyVcAQRFmZPmNqSyISlXA1tQCIxW+r478fty97XXAGjNYzBjpCsg==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/module-type-aliases": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", + "@types/react-router-config": "^5.0.7", + "combine-promises": "^1.1.0", "fs-extra": "^11.1.1", + "js-yaml": "^4.1.0", + "lodash": "^4.17.21", "tslib": "^2.6.0", + "utility-types": "^3.10.0", "webpack": "^5.88.1" }, "engines": { @@ -2995,36 +2986,18 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/plugin-content-pages/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@mdx-js/mdx": "^3.0.0", - "@slorber/remark-comment": "^1.0.0", - "escape-html": "^1.0.3", - "estree-util-value-to-estree": "^3.0.1", - "file-loader": "^6.2.0", + "node_modules/@docusaurus/plugin-content-pages": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-pages/-/plugin-content-pages-3.4.0.tgz", + "integrity": "sha512-h2+VN/0JjpR8fIkDEAoadNjfR3oLzB+v1qSXbIAKjQ46JAHx3X22n9nqS+BWSQnTnp1AjkjSvZyJMekmcwxzxg==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "fs-extra": "^11.1.1", - "image-size": "^1.0.2", - "mdast-util-mdx": "^3.0.0", - "mdast-util-to-string": "^4.0.0", - "rehype-raw": "^7.0.0", - "remark-directive": "^3.0.0", - "remark-emoji": "^4.0.0", - "remark-frontmatter": "^5.0.0", - "remark-gfm": "^4.0.0", - "stringify-object": "^3.3.0", "tslib": "^2.6.0", - "unified": "^11.0.3", - "unist-util-visit": "^5.0.0", - "url-loader": "^4.1.1", - "vfile": "^6.0.1", "webpack": "^5.88.1" }, "engines": { @@ -3036,13 +3009,13 @@ } }, "node_modules/@docusaurus/plugin-debug": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-debug/-/plugin-debug-3.1.1.tgz", - "integrity": "sha512-xWeMkueM9wE/8LVvl4+Qf1WqwXmreMjI5Kgr7GYCDoJ8zu4kD+KaMhrh7py7MNM38IFvU1RfrGKacCEe2DRRfQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-debug/-/plugin-debug-3.4.0.tgz", + "integrity": "sha512-uV7FDUNXGyDSD3PwUaf5YijX91T5/H9SX4ErEcshzwgzWwBtK37nUWPU3ZLJfeTavX3fycTOqk9TglpOLaWkCg==", "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", + "@docusaurus/core": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", "fs-extra": "^11.1.1", "react-json-view-lite": "^1.2.0", "tslib": "^2.6.0" @@ -3056,13 +3029,13 @@ } }, "node_modules/@docusaurus/plugin-google-tag-manager": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-google-tag-manager/-/plugin-google-tag-manager-3.1.1.tgz", - "integrity": "sha512-d07bsrMLdDIryDtY17DgqYUbjkswZQr8cLWl4tzXrt5OR/T/zxC1SYKajzB3fd87zTu5W5klV5GmUwcNSMXQXA==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-google-tag-manager/-/plugin-google-tag-manager-3.4.0.tgz", + "integrity": "sha512-O9tX1BTwxIhgXpOLpFDueYA9DWk69WCbDRrjYoMQtFHSkTyE7RhNgyjSPREUWJb9i+YUg3OrsvrBYRl64FCPCQ==", "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "@docusaurus/core": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "tslib": "^2.6.0" }, "engines": { @@ -3074,16 +3047,16 @@ } }, "node_modules/@docusaurus/plugin-ideal-image": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-ideal-image/-/plugin-ideal-image-3.1.1.tgz", - "integrity": "sha512-FYce5eV5/fWO4qIG8sKYdK3MTwusdxQML/M62IiltUNM/cqFkDrty1d+H+/I2PYX1s7AOoL3YomdJNP4vra/Tg==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-ideal-image/-/plugin-ideal-image-3.4.0.tgz", + "integrity": "sha512-s8N/PRiv1R66UY+WX/2E9a+GjkRooXVcf0VJNEYA3yZ6c24Path15ivjmdMtKaSo/6OXYbejGlA4DJZ5TPLkCQ==", "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/lqip-loader": "3.1.1", + "@docusaurus/core": "3.4.0", + "@docusaurus/lqip-loader": "3.4.0", "@docusaurus/responsive-loader": "^1.7.0", - "@docusaurus/theme-translations": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "@docusaurus/theme-translations": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "@slorber/react-ideal-image": "^0.0.12", "react-waypoint": "^10.3.0", "sharp": "^0.32.3", @@ -3105,16 +3078,16 @@ } }, "node_modules/@docusaurus/plugin-sitemap": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/plugin-sitemap/-/plugin-sitemap-3.1.1.tgz", - "integrity": "sha512-iJ4hCaMmDaUqRv131XJdt/C/jJQx8UreDWTRqZKtNydvZVh/o4yXGRRFOplea1D9b/zpwL1Y+ZDwX7xMhIOTmg==", - "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/logger": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-common": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/plugin-sitemap/-/plugin-sitemap-3.4.0.tgz", + "integrity": "sha512-+0VDvx9SmNrFNgwPoeoCha+tRoAjopwT0+pYO1xAbyLcewXSemq+eLxEa46Q1/aoOaJQ0qqHELuQM7iS2gp33Q==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "fs-extra": "^11.1.1", "sitemap": "^7.1.1", "tslib": "^2.6.0" @@ -3127,25 +3100,13 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/react-loadable": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz", - "integrity": "sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==", - "dependencies": { - "@types/react": "*", - "prop-types": "^15.6.2" - }, - "peerDependencies": { - "react": "*" - } - }, "node_modules/@docusaurus/remark-plugin-npm2yarn": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/remark-plugin-npm2yarn/-/remark-plugin-npm2yarn-3.1.1.tgz", - "integrity": "sha512-3dbQqXIOPIM6EYASWFodG+Ha5i8YGTPKukPYjupQeRzBGWXzunsr1z8voOjm+ljxSgRtgyZ7+q9tlpmYFi7x9A==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/remark-plugin-npm2yarn/-/remark-plugin-npm2yarn-3.4.0.tgz", + "integrity": "sha512-MXcYAkKu6544h7J4vbKdeH+G5HZf6LF3qZORQqWzxOi2p82PTLRu0YM6ZgzfPjH5nZClgLBHypPbyO9qhkxPKw==", "dependencies": { "mdast-util-mdx": "^3.0.0", - "npm-to-yarn": "^2.0.0", + "npm-to-yarn": "^2.2.1", "tslib": "^2.6.0", "unified": "^11.0.3", "unist-util-visit": "^5.0.0" @@ -3178,22 +3139,22 @@ } }, "node_modules/@docusaurus/theme-classic": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/theme-classic/-/theme-classic-3.1.1.tgz", - "integrity": "sha512-GiPE/jbWM8Qv1A14lk6s9fhc0LhPEQ00eIczRO4QL2nAQJZXkjPG6zaVx+1cZxPFWbAsqSjKe2lqkwF3fGkQ7Q==", - "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/module-type-aliases": "3.1.1", - "@docusaurus/plugin-content-blog": "3.1.1", - "@docusaurus/plugin-content-docs": "3.1.1", - "@docusaurus/plugin-content-pages": "3.1.1", - "@docusaurus/theme-common": "3.1.1", - "@docusaurus/theme-translations": "3.1.1", - "@docusaurus/types": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-common": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/theme-classic/-/theme-classic-3.4.0.tgz", + "integrity": "sha512-0IPtmxsBYv2adr1GnZRdMkEQt1YW6tpzrUPj02YxNpvJ5+ju4E13J5tB4nfdaen/tfR1hmpSPlTFPvTf4kwy8Q==", + "dependencies": { + "@docusaurus/core": "3.4.0", + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/module-type-aliases": "3.4.0", + "@docusaurus/plugin-content-blog": "3.4.0", + "@docusaurus/plugin-content-docs": "3.4.0", + "@docusaurus/plugin-content-pages": "3.4.0", + "@docusaurus/theme-common": "3.4.0", + "@docusaurus/theme-translations": "3.4.0", + "@docusaurus/types": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "@mdx-js/react": "^3.0.0", "clsx": "^2.0.0", "copy-text-to-clipboard": "^3.2.0", @@ -3216,58 +3177,18 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/theme-classic/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@mdx-js/mdx": "^3.0.0", - "@slorber/remark-comment": "^1.0.0", - "escape-html": "^1.0.3", - "estree-util-value-to-estree": "^3.0.1", - "file-loader": "^6.2.0", - "fs-extra": "^11.1.1", - "image-size": "^1.0.2", - "mdast-util-mdx": "^3.0.0", - "mdast-util-to-string": "^4.0.0", - "rehype-raw": "^7.0.0", - "remark-directive": "^3.0.0", - "remark-emoji": "^4.0.0", - "remark-frontmatter": "^5.0.0", - "remark-gfm": "^4.0.0", - "stringify-object": "^3.3.0", - "tslib": "^2.6.0", - "unified": "^11.0.3", - "unist-util-visit": "^5.0.0", - "url-loader": "^4.1.1", - "vfile": "^6.0.1", - "webpack": "^5.88.1" - }, - "engines": { - "node": ">=18.0" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, "node_modules/@docusaurus/theme-common": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/theme-common/-/theme-common-3.1.1.tgz", - "integrity": "sha512-38urZfeMhN70YaXkwIGXmcUcv2CEYK/2l4b05GkJPrbEbgpsIZM3Xc+Js2ehBGGZmfZq8GjjQ5RNQYG+MYzCYg==", - "dependencies": { - "@docusaurus/mdx-loader": "3.1.1", - "@docusaurus/module-type-aliases": "3.1.1", - "@docusaurus/plugin-content-blog": "3.1.1", - "@docusaurus/plugin-content-docs": "3.1.1", - "@docusaurus/plugin-content-pages": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-common": "3.1.1", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/theme-common/-/theme-common-3.4.0.tgz", + "integrity": "sha512-0A27alXuv7ZdCg28oPE8nH/Iz73/IUejVaCazqu9elS4ypjiLhK3KfzdSQBnL/g7YfHSlymZKdiOHEo8fJ0qMA==", + "dependencies": { + "@docusaurus/mdx-loader": "3.4.0", + "@docusaurus/module-type-aliases": "3.4.0", + "@docusaurus/plugin-content-blog": "3.4.0", + "@docusaurus/plugin-content-docs": "3.4.0", + "@docusaurus/plugin-content-pages": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", "@types/history": "^4.7.11", "@types/react": "*", "@types/react-router-config": "*", @@ -3285,59 +3206,19 @@ "react-dom": "^18.0.0" } }, - "node_modules/@docusaurus/theme-common/node_modules/@docusaurus/mdx-loader": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/mdx-loader/-/mdx-loader-3.1.1.tgz", - "integrity": "sha512-xN2IccH9+sv7TmxwsDJNS97BHdmlqWwho+kIVY4tcCXkp+k4QuzvWBeunIMzeayY4Fu13A6sAjHGv5qm72KyGA==", - "dependencies": { - "@babel/parser": "^7.22.7", - "@babel/traverse": "^7.22.8", - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", - "@mdx-js/mdx": "^3.0.0", - "@slorber/remark-comment": "^1.0.0", - "escape-html": "^1.0.3", - "estree-util-value-to-estree": "^3.0.1", - "file-loader": "^6.2.0", - "fs-extra": "^11.1.1", - "image-size": "^1.0.2", - "mdast-util-mdx": "^3.0.0", - "mdast-util-to-string": "^4.0.0", - "rehype-raw": "^7.0.0", - "remark-directive": "^3.0.0", - "remark-emoji": "^4.0.0", - "remark-frontmatter": "^5.0.0", - "remark-gfm": "^4.0.0", - "stringify-object": "^3.3.0", - "tslib": "^2.6.0", - "unified": "^11.0.3", - "unist-util-visit": "^5.0.0", - "url-loader": "^4.1.1", - "vfile": "^6.0.1", - "webpack": "^5.88.1" - }, - "engines": { - "node": ">=18.0" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, "node_modules/@docusaurus/theme-search-algolia": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/theme-search-algolia/-/theme-search-algolia-3.1.1.tgz", - "integrity": "sha512-tBH9VY5EpRctVdaAhT+b1BY8y5dyHVZGFXyCHgTrvcXQy5CV4q7serEX7U3SveNT9zksmchPyct6i1sFDC4Z5g==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/theme-search-algolia/-/theme-search-algolia-3.4.0.tgz", + "integrity": "sha512-aiHFx7OCw4Wck1z6IoShVdUWIjntC8FHCw9c5dR8r3q4Ynh+zkS8y2eFFunN/DL6RXPzpnvKCg3vhLQYJDmT9Q==", "dependencies": { "@docsearch/react": "^3.5.2", - "@docusaurus/core": "3.1.1", - "@docusaurus/logger": "3.1.1", - "@docusaurus/plugin-content-docs": "3.1.1", - "@docusaurus/theme-common": "3.1.1", - "@docusaurus/theme-translations": "3.1.1", - "@docusaurus/utils": "3.1.1", - "@docusaurus/utils-validation": "3.1.1", + "@docusaurus/core": "3.4.0", + "@docusaurus/logger": "3.4.0", + "@docusaurus/plugin-content-docs": "3.4.0", + "@docusaurus/theme-common": "3.4.0", + "@docusaurus/theme-translations": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-validation": "3.4.0", "algoliasearch": "^4.18.0", "algoliasearch-helper": "^3.13.3", "clsx": "^2.0.0", @@ -3356,9 +3237,9 @@ } }, "node_modules/@docusaurus/theme-translations": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/theme-translations/-/theme-translations-3.1.1.tgz", - "integrity": "sha512-xvWQFwjxHphpJq5fgk37FXCDdAa2o+r7FX8IpMg+bGZBNXyWBu3MjZ+G4+eUVNpDhVinTc+j6ucL0Ain5KCGrg==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/theme-translations/-/theme-translations-3.4.0.tgz", + "integrity": "sha512-zSxCSpmQCCdQU5Q4CnX/ID8CSUUI3fvmq4hU/GNP/XoAWtXo9SAVnM3TzpU8Gb//H3WCsT8mJcTfyOk3d9ftNg==", "dependencies": { "fs-extra": "^11.1.1", "tslib": "^2.6.0" @@ -3368,9 +3249,9 @@ } }, "node_modules/@docusaurus/types": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/types/-/types-3.1.1.tgz", - "integrity": "sha512-grBqOLnubUecgKFXN9q3uit2HFbCxTWX4Fam3ZFbMN0sWX9wOcDoA7lwdX/8AmeL20Oc4kQvWVgNrsT8bKRvzg==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/types/-/types-3.4.0.tgz", + "integrity": "sha512-4jcDO8kXi5Cf9TcyikB/yKmz14f2RZ2qTRerbHAsS+5InE9ZgSLBNLsewtFTcTOXSVcbU3FoGOzcNWAmU1TR0A==", "dependencies": { "@mdx-js/mdx": "^3.0.0", "@types/history": "^4.7.11", @@ -3388,12 +3269,13 @@ } }, "node_modules/@docusaurus/utils": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/utils/-/utils-3.1.1.tgz", - "integrity": "sha512-ZJfJa5cJQtRYtqijsPEnAZoduW6sjAQ7ZCWSZavLcV10Fw0Z3gSaPKA/B4micvj2afRZ4gZxT7KfYqe5H8Cetg==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/utils/-/utils-3.4.0.tgz", + "integrity": "sha512-fRwnu3L3nnWaXOgs88BVBmG1yGjcQqZNHG+vInhEa2Sz2oQB+ZjbEMO5Rh9ePFpZ0YDiDUhpaVjwmS+AU2F14g==", "dependencies": { - "@docusaurus/logger": "3.1.1", - "@svgr/webpack": "^6.5.1", + "@docusaurus/logger": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "@svgr/webpack": "^8.1.0", "escape-string-regexp": "^4.0.0", "file-loader": "^6.2.0", "fs-extra": "^11.1.1", @@ -3404,10 +3286,12 @@ "js-yaml": "^4.1.0", "lodash": "^4.17.21", "micromatch": "^4.0.5", + "prompts": "^2.4.2", "resolve-pathname": "^3.0.0", "shelljs": "^0.8.5", "tslib": "^2.6.0", "url-loader": "^4.1.1", + "utility-types": "^3.10.0", "webpack": "^5.88.1" }, "engines": { @@ -3423,9 +3307,9 @@ } }, "node_modules/@docusaurus/utils-common": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/utils-common/-/utils-common-3.1.1.tgz", - "integrity": "sha512-eGne3olsIoNfPug5ixjepZAIxeYFzHHnor55Wb2P57jNbtVaFvij/T+MS8U0dtZRFi50QU+UPmRrXdVUM8uyMg==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/utils-common/-/utils-common-3.4.0.tgz", + "integrity": "sha512-NVx54Wr4rCEKsjOH5QEVvxIqVvm+9kh7q8aYTU5WzUU9/Hctd6aTrcZ3G0Id4zYJ+AeaG5K5qHA4CY5Kcm2iyQ==", "dependencies": { "tslib": "^2.6.0" }, @@ -3442,14 +3326,17 @@ } }, "node_modules/@docusaurus/utils-validation": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@docusaurus/utils-validation/-/utils-validation-3.1.1.tgz", - "integrity": "sha512-KlY4P9YVDnwL+nExvlIpu79abfEv6ZCHuOX4ZQ+gtip+Wxj0daccdReIWWtqxM/Fb5Cz1nQvUCc7VEtT8IBUAA==", - "dependencies": { - "@docusaurus/logger": "3.1.1", - "@docusaurus/utils": "3.1.1", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/@docusaurus/utils-validation/-/utils-validation-3.4.0.tgz", + "integrity": "sha512-hYQ9fM+AXYVTWxJOT1EuNaRnrR2WGpRdLDQG07O8UOpsvCPWUVOeo26Rbm0JWY2sGLfzAb+tvJ62yF+8F+TV0g==", + "dependencies": { + "@docusaurus/logger": "3.4.0", + "@docusaurus/utils": "3.4.0", + "@docusaurus/utils-common": "3.4.0", + "fs-extra": "^11.2.0", "joi": "^17.9.2", "js-yaml": "^4.1.0", + "lodash": "^4.17.21", "tslib": "^2.6.0" }, "engines": { @@ -3470,22 +3357,22 @@ } }, "node_modules/@ionic-docs/preset-classic": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@ionic-docs/preset-classic/-/preset-classic-1.1.5.tgz", - "integrity": "sha512-nr50tkuPMyoz7f7X/fKulsVmJDcpezhogJX8XVJxRk8bc5/rNejc4Z6Eug4sEDcmgjmlE4PfF9TvBqvoUYFrmg==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@ionic-docs/preset-classic/-/preset-classic-1.2.7.tgz", + "integrity": "sha512-fQ0/VevFJkyc1PZz8oEC+ZOuFSpcG23PS073ddHiiPuUKwy0MDeXTMKMc+qPILgGi68u5QxbjX3xMC+4b1KHOA==", "dependencies": { "@csstools/postcss-cascade-layers": "^2.0.0", - "@docusaurus/core": "^3.1.0", - "@docusaurus/plugin-content-docs": "^3.1.0", - "@docusaurus/plugin-content-pages": "^3.1.0", - "@docusaurus/plugin-debug": "^3.1.0", - "@docusaurus/plugin-google-tag-manager": "^3.1.0", - "@docusaurus/plugin-ideal-image": "^3.1.0", - "@docusaurus/plugin-sitemap": "^3.1.0", - "@docusaurus/theme-classic": "^3.1.0", - "@docusaurus/theme-common": "^3.1.0", - "@docusaurus/theme-search-algolia": "^3.1.0", - "@ionic-docs/theme-classic": "^1.1.5", + "@docusaurus/core": "^3.4.0", + "@docusaurus/plugin-content-docs": "^3.4.0", + "@docusaurus/plugin-content-pages": "^3.4.0", + "@docusaurus/plugin-debug": "^3.4.0", + "@docusaurus/plugin-google-tag-manager": "^3.4.0", + "@docusaurus/plugin-ideal-image": "^3.4.0", + "@docusaurus/plugin-sitemap": "^3.4.0", + "@docusaurus/theme-classic": "^3.4.0", + "@docusaurus/theme-common": "^3.4.0", + "@docusaurus/theme-search-algolia": "^3.4.0", + "@ionic-docs/theme-classic": "^1.2.7", "@ionic-internal/design-system": "^0.0.1", "docusaurus-plugin-sass": "^0.2.5", "postcss-import": "^15.1.0", @@ -3500,11 +3387,11 @@ } }, "node_modules/@ionic-docs/theme-classic": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/@ionic-docs/theme-classic/-/theme-classic-1.1.5.tgz", - "integrity": "sha512-B9H7A4LloHBHRcvRr+GK70ux7lt+j6Rx3tKzU5bSPb7xK5taeaxm4IMjAVY9UYKBH7A1DyIBFIljkL1GNdLX/A==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@ionic-docs/theme-classic/-/theme-classic-1.2.7.tgz", + "integrity": "sha512-GbH/e+QMmhbmJ7qgy5Q5a+/jMnqXA9CvI8biGQYN10gzCfff1+P9pTvR7SSQ7iFcDmyEuhRU18QKMPazF1RRNQ==", "dependencies": { - "@docusaurus/theme-classic": "^3.1.0", + "@docusaurus/theme-classic": "^3.4.0", "@ionic-internal/design-system": "^0.0.1", "modern-normalize": "^2.0.0", "slugify": "^1.6.6" @@ -3667,9 +3554,9 @@ } }, "node_modules/@mdx-js/react": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@mdx-js/react/-/react-3.0.0.tgz", - "integrity": "sha512-nDctevR9KyYFyV+m+/+S4cpzCWHqj+iHDHq3QrsWezcC+B17uZdIWgCguESUkwFhM3n/56KxWVE3V6EokrmONQ==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@mdx-js/react/-/react-3.0.1.tgz", + "integrity": "sha512-9ZrPIU4MGf6et1m1ov3zKf+q9+deetI51zprKB1D/z3NOb+rUxxtEl3mCjW5wTGh6VhRdwPueh1oRzi6ezkA8A==", "dependencies": { "@types/mdx": "^2.0.0" }, @@ -3928,25 +3815,12 @@ "micromark-util-symbol": "^1.0.1" } }, - "node_modules/@slorber/static-site-generator-webpack-plugin": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/@slorber/static-site-generator-webpack-plugin/-/static-site-generator-webpack-plugin-4.0.7.tgz", - "integrity": "sha512-Ug7x6z5lwrz0WqdnNFOMYrDQNTPAprvHLSh6+/fmml3qUiz6l5eq+2MzLKWtn/q5K5NpSiFsZTP/fck/3vjSxA==", - "dependencies": { - "eval": "^0.1.8", - "p-map": "^4.0.0", - "webpack-sources": "^3.2.2" - }, - "engines": { - "node": ">=14" - } - }, "node_modules/@svgr/babel-plugin-add-jsx-attribute": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-6.5.1.tgz", - "integrity": "sha512-9PYGcXrAxitycIjRmZB+Q0JaN07GZIWaTBIGQzfaZv+qr1n8X1XUEJ5rZ/vx6OVD9RRYlrNnXWExQXcmZeD/BQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-8.0.0.tgz", + "integrity": "sha512-b9MIk7yhdS1pMCZM8VeNfUlSKVRhsHZNMl5O9SfaX0l0t5wjdgu4IDzGB8bpnGBBOjGST3rRFVsaaEtI4W6f7g==", "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -3987,11 +3861,11 @@ } }, "node_modules/@svgr/babel-plugin-replace-jsx-attribute-value": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-replace-jsx-attribute-value/-/babel-plugin-replace-jsx-attribute-value-6.5.1.tgz", - "integrity": "sha512-8DPaVVE3fd5JKuIC29dqyMB54sA6mfgki2H2+swh+zNJoynC8pMPzOkidqHOSc6Wj032fhl8Z0TVn1GiPpAiJg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-replace-jsx-attribute-value/-/babel-plugin-replace-jsx-attribute-value-8.0.0.tgz", + "integrity": "sha512-KVQ+PtIjb1BuYT3ht8M5KbzWBhdAjjUPdlMtpuw/VjT8coTrItWX6Qafl9+ji831JaJcu6PJNKCV0bp01lBNzQ==", "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4002,11 +3876,11 @@ } }, "node_modules/@svgr/babel-plugin-svg-dynamic-title": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-svg-dynamic-title/-/babel-plugin-svg-dynamic-title-6.5.1.tgz", - "integrity": "sha512-FwOEi0Il72iAzlkaHrlemVurgSQRDFbk0OC8dSvD5fSBPHltNh7JtLsxmZUhjYBZo2PpcU/RJvvi6Q0l7O7ogw==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-svg-dynamic-title/-/babel-plugin-svg-dynamic-title-8.0.0.tgz", + "integrity": "sha512-omNiKqwjNmOQJ2v6ge4SErBbkooV2aAWwaPFs2vUY7p7GhVkzRkJ00kILXQvRhA6miHnNpXv7MRnnSjdRjK8og==", "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4017,11 +3891,11 @@ } }, "node_modules/@svgr/babel-plugin-svg-em-dimensions": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-svg-em-dimensions/-/babel-plugin-svg-em-dimensions-6.5.1.tgz", - "integrity": "sha512-gWGsiwjb4tw+ITOJ86ndY/DZZ6cuXMNE/SjcDRg+HLuCmwpcjOktwRF9WgAiycTqJD/QXqL2f8IzE2Rzh7aVXA==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-svg-em-dimensions/-/babel-plugin-svg-em-dimensions-8.0.0.tgz", + "integrity": "sha512-mURHYnu6Iw3UBTbhGwE/vsngtCIbHE43xCRK7kCw4t01xyGqb2Pd+WXekRRoFOBIY29ZoOhUCTEweDMdrjfi9g==", "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4032,11 +3906,11 @@ } }, "node_modules/@svgr/babel-plugin-transform-react-native-svg": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-transform-react-native-svg/-/babel-plugin-transform-react-native-svg-6.5.1.tgz", - "integrity": "sha512-2jT3nTayyYP7kI6aGutkyfJ7UMGtuguD72OjeGLwVNyfPRBD8zQthlvL+fAbAKk5n9ZNcvFkp/b1lZ7VsYqVJg==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-transform-react-native-svg/-/babel-plugin-transform-react-native-svg-8.1.0.tgz", + "integrity": "sha512-Tx8T58CHo+7nwJ+EhUwx3LfdNSG9R2OKfaIXXs5soiy5HtgoAEkDay9LIimLOcG8dJQH1wPZp/cnAv6S9CrR1Q==", "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4047,9 +3921,9 @@ } }, "node_modules/@svgr/babel-plugin-transform-svg-component": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-transform-svg-component/-/babel-plugin-transform-svg-component-6.5.1.tgz", - "integrity": "sha512-a1p6LF5Jt33O3rZoVRBqdxL350oge54iZWHNI6LJB5tQ7EelvD/Mb1mfBiZNAan0dt4i3VArkFRjA4iObuNykQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-plugin-transform-svg-component/-/babel-plugin-transform-svg-component-8.0.0.tgz", + "integrity": "sha512-DFx8xa3cZXTdb/k3kfPeaixecQLgKh5NVBMwD0AQxOzcZawK4oo1Jh9LbrcACUivsCA7TLG8eeWgrDXjTMhRmw==", "engines": { "node": ">=12" }, @@ -4062,21 +3936,21 @@ } }, "node_modules/@svgr/babel-preset": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/babel-preset/-/babel-preset-6.5.1.tgz", - "integrity": "sha512-6127fvO/FF2oi5EzSQOAjo1LE3OtNVh11R+/8FXa+mHx1ptAaS4cknIjnUA7e6j6fwGGJ17NzaTJFUwOV2zwCw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/babel-preset/-/babel-preset-8.1.0.tgz", + "integrity": "sha512-7EYDbHE7MxHpv4sxvnVPngw5fuR6pw79SkcrILHJ/iMpuKySNCl5W1qcwPEpU+LgyRXOaAFgH0KhwD18wwg6ug==", "dependencies": { - "@svgr/babel-plugin-add-jsx-attribute": "^6.5.1", - "@svgr/babel-plugin-remove-jsx-attribute": "*", - "@svgr/babel-plugin-remove-jsx-empty-expression": "*", - "@svgr/babel-plugin-replace-jsx-attribute-value": "^6.5.1", - "@svgr/babel-plugin-svg-dynamic-title": "^6.5.1", - "@svgr/babel-plugin-svg-em-dimensions": "^6.5.1", - "@svgr/babel-plugin-transform-react-native-svg": "^6.5.1", - "@svgr/babel-plugin-transform-svg-component": "^6.5.1" + "@svgr/babel-plugin-add-jsx-attribute": "8.0.0", + "@svgr/babel-plugin-remove-jsx-attribute": "8.0.0", + "@svgr/babel-plugin-remove-jsx-empty-expression": "8.0.0", + "@svgr/babel-plugin-replace-jsx-attribute-value": "8.0.0", + "@svgr/babel-plugin-svg-dynamic-title": "8.0.0", + "@svgr/babel-plugin-svg-em-dimensions": "8.0.0", + "@svgr/babel-plugin-transform-react-native-svg": "8.1.0", + "@svgr/babel-plugin-transform-svg-component": "8.0.0" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4087,18 +3961,18 @@ } }, "node_modules/@svgr/core": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/core/-/core-6.5.1.tgz", - "integrity": "sha512-/xdLSWxK5QkqG524ONSjvg3V/FkNyCv538OIBdQqPNaAta3AsXj/Bd2FbvR87yMbXO2hFSWiAe/Q6IkVPDw+mw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/core/-/core-8.1.0.tgz", + "integrity": "sha512-8QqtOQT5ACVlmsvKOJNEaWmRPmcojMOzCz4Hs2BGG/toAp/K38LcsMRyLp349glq5AzJbCEeimEoxaX6v/fLrA==", "dependencies": { - "@babel/core": "^7.19.6", - "@svgr/babel-preset": "^6.5.1", - "@svgr/plugin-jsx": "^6.5.1", + "@babel/core": "^7.21.3", + "@svgr/babel-preset": "8.1.0", "camelcase": "^6.2.0", - "cosmiconfig": "^7.0.1" + "cosmiconfig": "^8.1.3", + "snake-case": "^3.0.4" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4106,15 +3980,15 @@ } }, "node_modules/@svgr/hast-util-to-babel-ast": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/hast-util-to-babel-ast/-/hast-util-to-babel-ast-6.5.1.tgz", - "integrity": "sha512-1hnUxxjd83EAxbL4a0JDJoD3Dao3hmjvyvyEV8PzWmLK3B9m9NPlW7GKjFyoWE8nM7HnXzPcmmSyOW8yOddSXw==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@svgr/hast-util-to-babel-ast/-/hast-util-to-babel-ast-8.0.0.tgz", + "integrity": "sha512-EbDKwO9GpfWP4jN9sGdYwPBU0kdomaPIL2Eu4YwmgP+sJeXT+L7bMwJUBnhzfH8Q2qMBqZ4fJwpCyYsAN3mt2Q==", "dependencies": { - "@babel/types": "^7.20.0", + "@babel/types": "^7.21.3", "entities": "^4.4.0" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4122,37 +3996,37 @@ } }, "node_modules/@svgr/plugin-jsx": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/plugin-jsx/-/plugin-jsx-6.5.1.tgz", - "integrity": "sha512-+UdQxI3jgtSjCykNSlEMuy1jSRQlGC7pqBCPvkG/2dATdWo082zHTTK3uhnAju2/6XpE6B5mZ3z4Z8Ns01S8Gw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/plugin-jsx/-/plugin-jsx-8.1.0.tgz", + "integrity": "sha512-0xiIyBsLlr8quN+WyuxooNW9RJ0Dpr8uOnH/xrCVO8GLUcwHISwj1AG0k+LFzteTkAA0GbX0kj9q6Dk70PTiPA==", "dependencies": { - "@babel/core": "^7.19.6", - "@svgr/babel-preset": "^6.5.1", - "@svgr/hast-util-to-babel-ast": "^6.5.1", + "@babel/core": "^7.21.3", + "@svgr/babel-preset": "8.1.0", + "@svgr/hast-util-to-babel-ast": "8.0.0", "svg-parser": "^2.0.4" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", "url": "https://github.com/sponsors/gregberge" }, "peerDependencies": { - "@svgr/core": "^6.0.0" + "@svgr/core": "*" } }, "node_modules/@svgr/plugin-svgo": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/plugin-svgo/-/plugin-svgo-6.5.1.tgz", - "integrity": "sha512-omvZKf8ixP9z6GWgwbtmP9qQMPX4ODXi+wzbVZgomNFsUIlHA1sf4fThdwTWSsZGgvGAG6yE+b/F5gWUkcZ/iQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/plugin-svgo/-/plugin-svgo-8.1.0.tgz", + "integrity": "sha512-Ywtl837OGO9pTLIN/onoWLmDQ4zFUycI1g76vuKGEz6evR/ZTJlJuz3G/fIkb6OVBJ2g0o6CGJzaEjfmEo3AHA==", "dependencies": { - "cosmiconfig": "^7.0.1", - "deepmerge": "^4.2.2", - "svgo": "^2.8.0" + "cosmiconfig": "^8.1.3", + "deepmerge": "^4.3.1", + "svgo": "^3.0.2" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4163,21 +4037,21 @@ } }, "node_modules/@svgr/webpack": { - "version": "6.5.1", - "resolved": "https://registry.npmjs.org/@svgr/webpack/-/webpack-6.5.1.tgz", - "integrity": "sha512-cQ/AsnBkXPkEK8cLbv4Dm7JGXq2XrumKnL1dRpJD9rIO2fTIlJI9a1uCciYG1F2aUsox/hJQyNGbt3soDxSRkA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@svgr/webpack/-/webpack-8.1.0.tgz", + "integrity": "sha512-LnhVjMWyMQV9ZmeEy26maJk+8HTIbd59cH4F2MJ439k9DqejRisfFNGAPvRYlKETuh9LrImlS8aKsBgKjMA8WA==", "dependencies": { - "@babel/core": "^7.19.6", - "@babel/plugin-transform-react-constant-elements": "^7.18.12", - "@babel/preset-env": "^7.19.4", + "@babel/core": "^7.21.3", + "@babel/plugin-transform-react-constant-elements": "^7.21.3", + "@babel/preset-env": "^7.20.2", "@babel/preset-react": "^7.18.6", - "@babel/preset-typescript": "^7.18.6", - "@svgr/core": "^6.5.1", - "@svgr/plugin-jsx": "^6.5.1", - "@svgr/plugin-svgo": "^6.5.1" + "@babel/preset-typescript": "^7.21.0", + "@svgr/core": "8.1.0", + "@svgr/plugin-jsx": "8.1.0", + "@svgr/plugin-svgo": "8.1.0" }, "engines": { - "node": ">=10" + "node": ">=14" }, "funding": { "type": "github", @@ -4867,30 +4741,31 @@ } }, "node_modules/algoliasearch": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/algoliasearch/-/algoliasearch-4.22.1.tgz", - "integrity": "sha512-jwydKFQJKIx9kIZ8Jm44SdpigFwRGPESaxZBaHSV0XWN2yBJAOT4mT7ppvlrpA4UGzz92pqFnVKr/kaZXrcreg==", - "dependencies": { - "@algolia/cache-browser-local-storage": "4.22.1", - "@algolia/cache-common": "4.22.1", - "@algolia/cache-in-memory": "4.22.1", - "@algolia/client-account": "4.22.1", - "@algolia/client-analytics": "4.22.1", - "@algolia/client-common": "4.22.1", - "@algolia/client-personalization": "4.22.1", - "@algolia/client-search": "4.22.1", - "@algolia/logger-common": "4.22.1", - "@algolia/logger-console": "4.22.1", - "@algolia/requester-browser-xhr": "4.22.1", - "@algolia/requester-common": "4.22.1", - "@algolia/requester-node-http": "4.22.1", - "@algolia/transporter": "4.22.1" + "version": "4.23.3", + "resolved": "https://registry.npmjs.org/algoliasearch/-/algoliasearch-4.23.3.tgz", + "integrity": "sha512-Le/3YgNvjW9zxIQMRhUHuhiUjAlKY/zsdZpfq4dlLqg6mEm0nL6yk+7f2hDOtLpxsgE4jSzDmvHL7nXdBp5feg==", + "dependencies": { + "@algolia/cache-browser-local-storage": "4.23.3", + "@algolia/cache-common": "4.23.3", + "@algolia/cache-in-memory": "4.23.3", + "@algolia/client-account": "4.23.3", + "@algolia/client-analytics": "4.23.3", + "@algolia/client-common": "4.23.3", + "@algolia/client-personalization": "4.23.3", + "@algolia/client-search": "4.23.3", + "@algolia/logger-common": "4.23.3", + "@algolia/logger-console": "4.23.3", + "@algolia/recommend": "4.23.3", + "@algolia/requester-browser-xhr": "4.23.3", + "@algolia/requester-common": "4.23.3", + "@algolia/requester-node-http": "4.23.3", + "@algolia/transporter": "4.23.3" } }, "node_modules/algoliasearch-helper": { - "version": "3.16.1", - "resolved": "https://registry.npmjs.org/algoliasearch-helper/-/algoliasearch-helper-3.16.1.tgz", - "integrity": "sha512-qxAHVjjmT7USVvrM8q6gZGaJlCK1fl4APfdAA7o8O6iXEc68G0xMNrzRkxoB/HmhhvyHnoteS/iMTiHiTcQQcg==", + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/algoliasearch-helper/-/algoliasearch-helper-3.21.0.tgz", + "integrity": "sha512-hjVOrL15I3Y3K8xG0icwG1/tWE+MocqBrhW6uVBWpU+/kVEMK0BnM2xdssj6mZM61eJ4iRxHR0djEI3ENOpR8w==", "dependencies": { "@algolia/events": "^4.0.1" }, @@ -5010,7 +4885,8 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/array-timsort/-/array-timsort-1.0.3.tgz", "integrity": "sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/array-union": { "version": "2.1.0", @@ -5037,9 +4913,9 @@ } }, "node_modules/autoprefixer": { - "version": "10.4.16", - "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.16.tgz", - "integrity": "sha512-7vd3UC6xKp0HLfua5IjZlcXvGAGy7cBAXTg2lyQ/8WpNhd6SiZ8Be+xm3FyBSYJx5GKcpRCzBh7RH4/0dnY+uQ==", + "version": "10.4.19", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.19.tgz", + "integrity": "sha512-BaENR2+zBZ8xXhM4pUaKUxlVdxZ0EZhjvbopwnXmxRUfqDmwSpC2lAi/QXvx7NRdPCo1WKEcEF6mV64si1z4Ew==", "funding": [ { "type": "opencollective", @@ -5055,9 +4931,9 @@ } ], "dependencies": { - "browserslist": "^4.21.10", - "caniuse-lite": "^1.0.30001538", - "fraction.js": "^4.3.6", + "browserslist": "^4.23.0", + "caniuse-lite": "^1.0.30001599", + "fraction.js": "^4.3.7", "normalize-range": "^0.1.2", "picocolors": "^1.0.0", "postcss-value-parser": "^4.2.0" @@ -5073,9 +4949,9 @@ } }, "node_modules/b4a": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz", - "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==" + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.6.tgz", + "integrity": "sha512-5Tk1HLk6b6ctmjIkAcU/Ujv/1WqiDl0F0JdRCR80VsOcUlHcu7pWeWRlOqQLHfDEsVx9YH/aif5AG4ehoCtTmg==" }, "node_modules/babel-loader": { "version": "9.1.3", @@ -5159,6 +5035,47 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/bare-events": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.3.1.tgz", + "integrity": "sha512-sJnSOTVESURZ61XgEleqmP255T6zTYwHPwE4r6SssIh0U9/uDvfpdoJYpVUerJJZH2fueO+CdT8ZT+OC/7aZDA==", + "optional": true + }, + "node_modules/bare-fs": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-2.3.1.tgz", + "integrity": "sha512-W/Hfxc/6VehXlsgFtbB5B4xFcsCl+pAh30cYhoFyXErf6oGrwjh8SwiPAdHgpmWonKuYpZgGywN0SXt7dgsADA==", + "optional": true, + "dependencies": { + "bare-events": "^2.0.0", + "bare-path": "^2.0.0", + "bare-stream": "^2.0.0" + } + }, + "node_modules/bare-os": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/bare-os/-/bare-os-2.3.0.tgz", + "integrity": "sha512-oPb8oMM1xZbhRQBngTgpcQ5gXw6kjOaRsSWsIeNyRxGed2w/ARyP7ScBYpWR1qfX2E5rS3gBw6OWcSQo+s+kUg==", + "optional": true + }, + "node_modules/bare-path": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-2.1.3.tgz", + "integrity": "sha512-lh/eITfU8hrj9Ru5quUp0Io1kJWIk1bTjzo7JH1P5dWmQ2EL4hFUlfI8FonAhSlgIfhn63p84CDY/x+PisgcXA==", + "optional": true, + "dependencies": { + "bare-os": "^2.1.0" + } + }, + "node_modules/bare-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/bare-stream/-/bare-stream-2.0.1.tgz", + "integrity": "sha512-ubLyoDqPnUf5o0kSFp709HC0WRZuxVuh4pbte5eY95Xvx5bdvz07c2JFmXBfqqe60q+9PJ8S4X5GRvmcNSKMxg==", + "optional": true, + "dependencies": { + "streamx": "^2.18.0" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -5300,20 +5217,21 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" } }, "node_modules/browserslist": { - "version": "4.22.2", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.22.2.tgz", - "integrity": "sha512-0UgcrvQmBDvZHFGdYUehrCNIazki7/lUP3kkoi/r3YB2amZbFM9J43ZRkJTXBUZK4gmx56+Sqk9+Vs9mwZx9+A==", + "version": "4.23.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", + "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", "funding": [ { "type": "opencollective", @@ -5329,8 +5247,8 @@ } ], "dependencies": { - "caniuse-lite": "^1.0.30001565", - "electron-to-chromium": "^1.4.601", + "caniuse-lite": "^1.0.30001587", + "electron-to-chromium": "^1.4.668", "node-releases": "^2.0.14", "update-browserslist-db": "^1.0.13" }, @@ -5482,9 +5400,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001568", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001568.tgz", - "integrity": "sha512-vSUkH84HontZJ88MiNrOau1EBrCqEQYgkC5gIySiDlpsm8sGVrhU7Kx4V6h0tnqaHzIHZv08HlJIwPbL4XL9+A==", + "version": "1.0.30001627", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001627.tgz", + "integrity": "sha512-4zgNiB8nTyV/tHhwZrFs88ryjls/lHiqFhrxCW4qSTeuRByBVnPYpDInchOIySWknznucaf31Z4KYqjfbrecVw==", "funding": [ { "type": "opencollective", @@ -5814,9 +5732,9 @@ } }, "node_modules/clsx": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.0.tgz", - "integrity": "sha512-m3iNNWpd9rl3jvvcBnu70ylMdrXt8Vlq4HYadnU5fwcOtvkSQWPmj7amUcDT2qYI7risszBjI5AUIUox9D16pg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", "engines": { "node": ">=6" } @@ -5903,10 +5821,11 @@ } }, "node_modules/comment-json": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-4.2.3.tgz", - "integrity": "sha512-SsxdiOf064DWoZLH799Ata6u7iV658A11PlWtZATDlXPpKGJnbJZ5Z24ybixAi+LUUqJ/GKowAejtC5GFUG7Tw==", + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-4.2.4.tgz", + "integrity": "sha512-E5AjpSW+O+N5T2GsOQMHLLsJvrYw6G/AFt9GvU6NguEAfzKShh7hRiLtVo6S9KbRpFMGqE5ojo0/hE+sdteWvQ==", "dev": true, + "license": "MIT", "dependencies": { "array-timsort": "^1.0.3", "core-util-is": "^1.0.3", @@ -6193,18 +6112,28 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, "node_modules/cosmiconfig": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.1.0.tgz", - "integrity": "sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==", + "version": "8.3.6", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", + "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", "dependencies": { - "@types/parse-json": "^4.0.0", - "import-fresh": "^3.2.1", - "parse-json": "^5.0.0", - "path-type": "^4.0.0", - "yaml": "^1.10.0" + "import-fresh": "^3.3.0", + "js-yaml": "^4.1.0", + "parse-json": "^5.2.0", + "path-type": "^4.0.0" }, "engines": { - "node": ">=10" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/d-fischer" + }, + "peerDependencies": { + "typescript": ">=4.9.5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } }, "node_modules/cross-spawn": { @@ -6246,27 +6175,28 @@ } }, "node_modules/cspell": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell/-/cspell-8.7.0.tgz", - "integrity": "sha512-77nRPgLl240C6FK8RKVKo34lP15Lzp/6bk+SKYJFwUKKXlcgWXDis+Lw4JolA741/JgHtuxmhW1C8P7dCKjJ3w==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell/-/cspell-8.10.4.tgz", + "integrity": "sha512-6eu42atG3ohf1r8vkRCKHBgUED+MOY7ErwPodeEtiHOqCXBtTCoPQXbqJozRy5Jfr2VMCMiryknxI4dH5yzjuQ==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-json-reporter": "8.7.0", - "@cspell/cspell-pipe": "8.7.0", - "@cspell/cspell-types": "8.7.0", - "@cspell/dynamic-import": "8.7.0", + "@cspell/cspell-json-reporter": "8.10.4", + "@cspell/cspell-pipe": "8.10.4", + "@cspell/cspell-types": "8.10.4", + "@cspell/dynamic-import": "8.10.4", "chalk": "^5.3.0", "chalk-template": "^1.1.0", - "commander": "^12.0.0", - "cspell-gitignore": "8.7.0", - "cspell-glob": "8.7.0", - "cspell-io": "8.7.0", - "cspell-lib": "8.7.0", + "commander": "^12.1.0", + "cspell-gitignore": "8.10.4", + "cspell-glob": "8.10.4", + "cspell-io": "8.10.4", + "cspell-lib": "8.10.4", "fast-glob": "^3.3.2", "fast-json-stable-stringify": "^2.1.0", "file-entry-cache": "^8.0.0", "get-stdin": "^9.0.0", - "semver": "^7.6.0", + "semver": "^7.6.2", "strip-ansi": "^7.1.0", "vscode-uri": "^3.0.8" }, @@ -6282,24 +6212,26 @@ } }, "node_modules/cspell-config-lib": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-8.7.0.tgz", - "integrity": "sha512-depsd01GbLBo71/tfRrL5iECWQLS4CjCxA9C01dVkFAJqVB0s+K9KLKjTlq5aHOhcvo9Z3dHV+bGQCf5/Q7bfw==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-8.10.4.tgz", + "integrity": "sha512-0VgnDEU4/+PWG+8x0FBN0QPun14sox9n7DBMvKGwAORhfiuYJ9w8kdrS/QqHdpHsRRQhXP1SWR8Nfg/5dUxsPg==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-types": "8.7.0", - "comment-json": "^4.2.3", - "yaml": "^2.4.1" + "@cspell/cspell-types": "8.10.4", + "comment-json": "^4.2.4", + "yaml": "^2.4.5" }, "engines": { "node": ">=18" } }, "node_modules/cspell-config-lib/node_modules/yaml": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.1.tgz", - "integrity": "sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==", + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.5.tgz", + "integrity": "sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==", "dev": true, + "license": "ISC", "bin": { "yaml": "bin.mjs" }, @@ -6308,14 +6240,15 @@ } }, "node_modules/cspell-dictionary": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-8.7.0.tgz", - "integrity": "sha512-S6IpZSzIMxlOO/33NgCOuP0TPH2mZbw8d5CP44z5jajflloq8l74MeJLkeDzYfCRcm0Rtk0A5drBeMg+Ai34OA==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-8.10.4.tgz", + "integrity": "sha512-9Hg2eTYbTKMoPy0r/IjGwcIII7PLGpeZlG1XzCDP4MW/bV4TGB6EfY8RAmhUt8cTwo7f6fxqu53WLaR3YPEozg==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.7.0", - "@cspell/cspell-types": "8.7.0", - "cspell-trie-lib": "8.7.0", + "@cspell/cspell-pipe": "8.10.4", + "@cspell/cspell-types": "8.10.4", + "cspell-trie-lib": "8.10.4", "fast-equals": "^5.0.1", "gensequence": "^7.0.0" }, @@ -6324,12 +6257,15 @@ } }, "node_modules/cspell-gitignore": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-gitignore/-/cspell-gitignore-8.7.0.tgz", - "integrity": "sha512-yvUZ86qyopUpDgn+YXP1qTpUe/lp65ZFvpMtw21lWHTFlg1OWKntr349EQU/5ben/K6koxk1FiElCBV7Lr4uFg==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-gitignore/-/cspell-gitignore-8.10.4.tgz", + "integrity": "sha512-OtN/nZAxgFYGdV+hCK8tF3drlGJJ+42W278cIM67H67cHYupVICFgsDLiNBz/iR/J9S4pEU5WXu2yPtHFHvVUQ==", "dev": true, + "license": "MIT", "dependencies": { - "cspell-glob": "8.7.0", + "@cspell/url": "8.10.4", + "cspell-glob": "8.10.4", + "cspell-io": "8.10.4", "find-up-simple": "^1.0.0" }, "bin": { @@ -6340,25 +6276,28 @@ } }, "node_modules/cspell-glob": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-8.7.0.tgz", - "integrity": "sha512-AMdfx0gvROA/aIL8t8b5Y5NtMgscGZELFj6WhCSZiQSuWRxXUKiLGGLUFjx2y0hgXN9LUYOo6aBjvhnxI/v71g==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-8.10.4.tgz", + "integrity": "sha512-HPRK6ZtHBzY/zGMhajzJ2MOgHMgY74/FijtaZkYc09QTEjONhIO4VWcrxrr1/qoM/qAp2Y/CKcBM/OOiHls7+A==", "dev": true, + "license": "MIT", "dependencies": { - "micromatch": "^4.0.5" + "@cspell/url": "8.10.4", + "micromatch": "^4.0.7" }, "engines": { "node": ">=18" } }, "node_modules/cspell-grammar": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-8.7.0.tgz", - "integrity": "sha512-SGcXc7322wU2WNRi7vtpToWDXTqZHhxqvR+aIXHT2kkxlMSWp3Rvfpshd0ckgY54nZtgw7R/JtKND2jeACRpwQ==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-8.10.4.tgz", + "integrity": "sha512-AW9JqEmMJLrbBwN/3BAwpHgOz5WFyb4syS+pjFRdZGx/w9e9ZSn4xyfnQ3mjNaFc/oZUcXy+q032bNZQppjGXA==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.7.0", - "@cspell/cspell-types": "8.7.0" + "@cspell/cspell-pipe": "8.10.4", + "@cspell/cspell-types": "8.10.4" }, "bin": { "cspell-grammar": "bin.mjs" @@ -6368,57 +6307,63 @@ } }, "node_modules/cspell-io": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-8.7.0.tgz", - "integrity": "sha512-o7OltyyvVkRG1gQrIqGpN5pUkHNnv6rvihb7Qu6cJ8jITinLGuWJuEQpgt0eF5yIr624jDbFwSzAxsFox8riQg==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-8.10.4.tgz", + "integrity": "sha512-IU+w0hNUQSR99ftC5Jr5D3Vtg70AOUSvdFXHO13qVf3GBnfYxbltQirbY5afLFUWDY6ayNO3GsZisCMdywmlwg==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-service-bus": "8.7.0" + "@cspell/cspell-service-bus": "8.10.4", + "@cspell/url": "8.10.4" }, "engines": { "node": ">=18" } }, "node_modules/cspell-lib": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-8.7.0.tgz", - "integrity": "sha512-qDSHZGekwiDmouYRECTQokE+hgAuPqREm+Hb+G3DoIo3ZK5H47TtEUo8fNCw22XsKefcF8X28LiyoZwiYHVpSg==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-8.10.4.tgz", + "integrity": "sha512-u1Edp5p2zwnBuQ9pBFg+YfAWB1c1uERWSZkteD5uClVz21zY5Aiikl41gOLi6Qm5+oWCWW+nP1HcC6B6wlFLHQ==", "dev": true, - "dependencies": { - "@cspell/cspell-bundled-dicts": "8.7.0", - "@cspell/cspell-pipe": "8.7.0", - "@cspell/cspell-resolver": "8.7.0", - "@cspell/cspell-types": "8.7.0", - "@cspell/dynamic-import": "8.7.0", - "@cspell/strong-weak-map": "8.7.0", + "license": "MIT", + "dependencies": { + "@cspell/cspell-bundled-dicts": "8.10.4", + "@cspell/cspell-pipe": "8.10.4", + "@cspell/cspell-resolver": "8.10.4", + "@cspell/cspell-types": "8.10.4", + "@cspell/dynamic-import": "8.10.4", + "@cspell/strong-weak-map": "8.10.4", + "@cspell/url": "8.10.4", "clear-module": "^4.1.2", - "comment-json": "^4.2.3", - "configstore": "^6.0.0", - "cspell-config-lib": "8.7.0", - "cspell-dictionary": "8.7.0", - "cspell-glob": "8.7.0", - "cspell-grammar": "8.7.0", - "cspell-io": "8.7.0", - "cspell-trie-lib": "8.7.0", + "comment-json": "^4.2.4", + "cspell-config-lib": "8.10.4", + "cspell-dictionary": "8.10.4", + "cspell-glob": "8.10.4", + "cspell-grammar": "8.10.4", + "cspell-io": "8.10.4", + "cspell-trie-lib": "8.10.4", + "env-paths": "^3.0.0", "fast-equals": "^5.0.1", "gensequence": "^7.0.0", "import-fresh": "^3.3.0", "resolve-from": "^5.0.0", "vscode-languageserver-textdocument": "^1.0.11", - "vscode-uri": "^3.0.8" + "vscode-uri": "^3.0.8", + "xdg-basedir": "^5.1.0" }, "engines": { "node": ">=18" } }, "node_modules/cspell-trie-lib": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-8.7.0.tgz", - "integrity": "sha512-W3Nh2cO7gMV91r+hLqyTMgKlvRl4W5diKs5YiyOxjZumRkMBy42IzcNYtgIIacOxghklv96F5Bd1Vx/zY6ylGA==", + "version": "8.10.4", + "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-8.10.4.tgz", + "integrity": "sha512-PQDwEYI10sp9nwnUA8HFFZr1c5j1Zrk9p8oqk7KUy+QUF3XcJn3ayLenPNUG95U/ysg3RBHc7/Vmh7unvXNRlQ==", "dev": true, + "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.7.0", - "@cspell/cspell-types": "8.7.0", + "@cspell/cspell-pipe": "8.10.4", + "@cspell/cspell-types": "8.10.4", "gensequence": "^7.0.0" }, "engines": { @@ -6430,6 +6375,7 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", "dev": true, + "license": "MIT", "engines": { "node": "^12.17.0 || ^14.13 || >=16.0.0" }, @@ -6438,20 +6384,21 @@ } }, "node_modules/cspell/node_modules/commander": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", - "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } }, "node_modules/css-declaration-sorter": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-6.4.1.tgz", - "integrity": "sha512-rtdthzxKuyq6IzqX6jEcIzQF/YqccluefyCYheovBOLhFT/drQA9zj/UbRAa9J7C0o6EG6u3E6g+vKkay7/k3g==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/css-declaration-sorter/-/css-declaration-sorter-7.2.0.tgz", + "integrity": "sha512-h70rUM+3PNFuaBDTLe8wF/cdWu+dOZmb7pJt8Z2sedYbAcQVQV/tEchueg3GWxwqS0cxtbxmaHEdkNACqcvsow==", "engines": { - "node": "^10 || ^12 || >=14" + "node": "^14 || ^16 || >=18" }, "peerDependencies": { "postcss": "^8.0.9" @@ -6483,16 +6430,16 @@ } }, "node_modules/css-minimizer-webpack-plugin": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/css-minimizer-webpack-plugin/-/css-minimizer-webpack-plugin-4.2.2.tgz", - "integrity": "sha512-s3Of/4jKfw1Hj9CxEO1E5oXhQAxlayuHO2y/ML+C6I9sQ7FdzfEV6QgMLN3vI+qFsjJGIAFLKtQK7t8BOXAIyA==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/css-minimizer-webpack-plugin/-/css-minimizer-webpack-plugin-5.0.1.tgz", + "integrity": "sha512-3caImjKFQkS+ws1TGcFn0V1HyDJFq1Euy589JlD6/3rV2kj+w7r5G9WDMgSHvpvXHNZ2calVypZWuEDQd9wfLg==", "dependencies": { - "cssnano": "^5.1.8", - "jest-worker": "^29.1.2", - "postcss": "^8.4.17", - "schema-utils": "^4.0.0", - "serialize-javascript": "^6.0.0", - "source-map": "^0.6.1" + "@jridgewell/trace-mapping": "^0.3.18", + "cssnano": "^6.0.1", + "jest-worker": "^29.4.3", + "postcss": "^8.4.24", + "schema-utils": "^4.0.1", + "serialize-javascript": "^6.0.1" }, "engines": { "node": ">= 14.15.0" @@ -6525,14 +6472,6 @@ } } }, - "node_modules/css-minimizer-webpack-plugin/node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -6549,23 +6488,15 @@ } }, "node_modules/css-tree": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.1.3.tgz", - "integrity": "sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", + "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", "dependencies": { - "mdn-data": "2.0.14", - "source-map": "^0.6.1" + "mdn-data": "2.0.30", + "source-map-js": "^1.0.1" }, "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/css-tree/node_modules/source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "engines": { - "node": ">=0.10.0" + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" } }, "node_modules/css-what": { @@ -6591,108 +6522,128 @@ } }, "node_modules/cssnano": { - "version": "5.1.15", - "resolved": "https://registry.npmjs.org/cssnano/-/cssnano-5.1.15.tgz", - "integrity": "sha512-j+BKgDcLDQA+eDifLx0EO4XSA56b7uut3BQFH+wbSaSTuGLuiyTa/wbRYthUXX8LC9mLg+WWKe8h+qJuwTAbHw==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/cssnano/-/cssnano-6.1.2.tgz", + "integrity": "sha512-rYk5UeX7VAM/u0lNqewCdasdtPK81CgX8wJFLEIXHbV2oldWRgJAsZrdhRXkV1NJzA2g850KiFm9mMU2HxNxMA==", "dependencies": { - "cssnano-preset-default": "^5.2.14", - "lilconfig": "^2.0.3", - "yaml": "^1.10.2" + "cssnano-preset-default": "^6.1.2", + "lilconfig": "^3.1.1" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/cssnano" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/cssnano-preset-advanced": { - "version": "5.3.10", - "resolved": "https://registry.npmjs.org/cssnano-preset-advanced/-/cssnano-preset-advanced-5.3.10.tgz", - "integrity": "sha512-fnYJyCS9jgMU+cmHO1rPSPf9axbQyD7iUhLO5Df6O4G+fKIOMps+ZbU0PdGFejFBBZ3Pftf18fn1eG7MAPUSWQ==", + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/cssnano-preset-advanced/-/cssnano-preset-advanced-6.1.2.tgz", + "integrity": "sha512-Nhao7eD8ph2DoHolEzQs5CfRpiEP0xa1HBdnFZ82kvqdmbwVBUr2r1QuQ4t1pi+D1ZpqpcO4T+wy/7RxzJ/WPQ==", "dependencies": { - "autoprefixer": "^10.4.12", - "cssnano-preset-default": "^5.2.14", - "postcss-discard-unused": "^5.1.0", - "postcss-merge-idents": "^5.1.1", - "postcss-reduce-idents": "^5.2.0", - "postcss-zindex": "^5.1.0" + "autoprefixer": "^10.4.19", + "browserslist": "^4.23.0", + "cssnano-preset-default": "^6.1.2", + "postcss-discard-unused": "^6.0.5", + "postcss-merge-idents": "^6.0.3", + "postcss-reduce-idents": "^6.0.3", + "postcss-zindex": "^6.0.2" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/cssnano-preset-default": { - "version": "5.2.14", - "resolved": "https://registry.npmjs.org/cssnano-preset-default/-/cssnano-preset-default-5.2.14.tgz", - "integrity": "sha512-t0SFesj/ZV2OTylqQVOrFgEh5uanxbO6ZAdeCrNsUQ6fVuXwYTxJPNAGvGTxHbD68ldIJNec7PyYZDBrfDQ+6A==", - "dependencies": { - "css-declaration-sorter": "^6.3.1", - "cssnano-utils": "^3.1.0", - "postcss-calc": "^8.2.3", - "postcss-colormin": "^5.3.1", - "postcss-convert-values": "^5.1.3", - "postcss-discard-comments": "^5.1.2", - "postcss-discard-duplicates": "^5.1.0", - "postcss-discard-empty": "^5.1.1", - "postcss-discard-overridden": "^5.1.0", - "postcss-merge-longhand": "^5.1.7", - "postcss-merge-rules": "^5.1.4", - "postcss-minify-font-values": "^5.1.0", - "postcss-minify-gradients": "^5.1.1", - "postcss-minify-params": "^5.1.4", - "postcss-minify-selectors": "^5.2.1", - "postcss-normalize-charset": "^5.1.0", - "postcss-normalize-display-values": "^5.1.0", - "postcss-normalize-positions": "^5.1.1", - "postcss-normalize-repeat-style": "^5.1.1", - "postcss-normalize-string": "^5.1.0", - "postcss-normalize-timing-functions": "^5.1.0", - "postcss-normalize-unicode": "^5.1.1", - "postcss-normalize-url": "^5.1.0", - "postcss-normalize-whitespace": "^5.1.1", - "postcss-ordered-values": "^5.1.3", - "postcss-reduce-initial": "^5.1.2", - "postcss-reduce-transforms": "^5.1.0", - "postcss-svgo": "^5.1.0", - "postcss-unique-selectors": "^5.1.1" - }, - "engines": { - "node": "^10 || ^12 || >=14.0" + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/cssnano-preset-default/-/cssnano-preset-default-6.1.2.tgz", + "integrity": "sha512-1C0C+eNaeN8OcHQa193aRgYexyJtU8XwbdieEjClw+J9d94E41LwT6ivKH0WT+fYwYWB0Zp3I3IZ7tI/BbUbrg==", + "dependencies": { + "browserslist": "^4.23.0", + "css-declaration-sorter": "^7.2.0", + "cssnano-utils": "^4.0.2", + "postcss-calc": "^9.0.1", + "postcss-colormin": "^6.1.0", + "postcss-convert-values": "^6.1.0", + "postcss-discard-comments": "^6.0.2", + "postcss-discard-duplicates": "^6.0.3", + "postcss-discard-empty": "^6.0.3", + "postcss-discard-overridden": "^6.0.2", + "postcss-merge-longhand": "^6.0.5", + "postcss-merge-rules": "^6.1.1", + "postcss-minify-font-values": "^6.1.0", + "postcss-minify-gradients": "^6.0.3", + "postcss-minify-params": "^6.1.0", + "postcss-minify-selectors": "^6.0.4", + "postcss-normalize-charset": "^6.0.2", + "postcss-normalize-display-values": "^6.0.2", + "postcss-normalize-positions": "^6.0.2", + "postcss-normalize-repeat-style": "^6.0.2", + "postcss-normalize-string": "^6.0.2", + "postcss-normalize-timing-functions": "^6.0.2", + "postcss-normalize-unicode": "^6.1.0", + "postcss-normalize-url": "^6.0.2", + "postcss-normalize-whitespace": "^6.0.2", + "postcss-ordered-values": "^6.0.2", + "postcss-reduce-initial": "^6.1.0", + "postcss-reduce-transforms": "^6.0.2", + "postcss-svgo": "^6.0.3", + "postcss-unique-selectors": "^6.0.4" + }, + "engines": { + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/cssnano-utils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/cssnano-utils/-/cssnano-utils-3.1.0.tgz", - "integrity": "sha512-JQNR19/YZhz4psLX/rQ9M83e3z2Wf/HdJbryzte4a3NSuafyp9w/I4U+hx5C2S9g41qlstH7DEWnZaaj83OuEA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/cssnano-utils/-/cssnano-utils-4.0.2.tgz", + "integrity": "sha512-ZR1jHg+wZ8o4c3zqf1SIUSTIvm/9mU343FMR6Obe/unskbvpGhZOo1J6d/r8D1pzkRQYuwbcH3hToOuoA2G7oQ==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/csso": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/csso/-/csso-4.2.0.tgz", - "integrity": "sha512-wvlcdIbf6pwKEk7vHj8/Bkc0B4ylXZruLvOgs9doS5eOsOpuodOV2zJChSpkp+pRpYQLQMeF04nr3Z68Sta9jA==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", + "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", "dependencies": { - "css-tree": "^1.1.2" + "css-tree": "~2.2.0" }, "engines": { - "node": ">=8.0.0" + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/csso/node_modules/css-tree": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", + "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", + "dependencies": { + "mdn-data": "2.0.28", + "source-map-js": "^1.0.1" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" } }, + "node_modules/csso/node_modules/mdn-data": { + "version": "2.0.28", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", + "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==" + }, "node_modules/csstype": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", @@ -6867,9 +6818,9 @@ } }, "node_modules/detect-libc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", - "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", + "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", "engines": { "node": ">=8" } @@ -7078,9 +7029,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.610", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.610.tgz", - "integrity": "sha512-mqi2oL1mfeHYtOdCxbPQYV/PL7YrQlxbvFEZ0Ee8GbDdShimqt2/S6z2RWqysuvlwdOrQdqvE0KZrBTipAeJzg==" + "version": "1.4.789", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.789.tgz", + "integrity": "sha512-0VbyiaXoT++Fi2vHGo2ThOeS6X3vgRCWrjPeO2FeIAWL6ItiSJ9BqlH8LfCXe3X1IdcG+S0iLoNaxQWhfZoGzQ==" }, "node_modules/emoji-regex": { "version": "9.2.2", @@ -7148,6 +7099,18 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/env-paths": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz", + "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -7317,16 +7280,13 @@ } }, "node_modules/estree-util-value-to-estree": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/estree-util-value-to-estree/-/estree-util-value-to-estree-3.0.1.tgz", - "integrity": "sha512-b2tdzTurEIbwRh+mKrEcaWfu1wgb8J1hVsgREg7FFiecWwK/PhO8X0kyc+0bIcKNtD4sqxIdNoRy6/p/TvECEA==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/estree-util-value-to-estree/-/estree-util-value-to-estree-3.1.1.tgz", + "integrity": "sha512-5mvUrF2suuv5f5cGDnDphIy4/gW86z82kl5qG6mM9z04SEQI4FB5Apmaw/TGEf3l55nLtMs5s51dmhUzvAHQCA==", "dependencies": { "@types/estree": "^1.0.0", "is-plain-obj": "^4.0.0" }, - "engines": { - "node": ">=16.0.0" - }, "funding": { "url": "https://github.com/sponsors/remcohaszing" } @@ -7543,6 +7503,7 @@ "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.0.1.tgz", "integrity": "sha512-WF1Wi8PwwSY7/6Kx0vKXtw8RwuSGoM1bvDaJbu7MxDlR1vovZjIAKrnzyrThgAjm6JDTu0fVgWXDlMGspodfoQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -7707,9 +7668,10 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -8146,6 +8108,7 @@ "resolved": "https://registry.npmjs.org/gensequence/-/gensequence-7.0.0.tgz", "integrity": "sha512-47Frx13aZh01afHJTB3zTtKIlFI6vWY+MYCN9Qpew6i52rfKjnhCF/l1YlC8UmEMvvntZZ6z4PiCcmyuedR2aQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" } @@ -8254,6 +8217,7 @@ "resolved": "https://registry.npmjs.org/global-directory/-/global-directory-4.0.1.tgz", "integrity": "sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==", "dev": true, + "license": "MIT", "dependencies": { "ini": "4.1.1" }, @@ -8470,6 +8434,7 @@ "resolved": "https://registry.npmjs.org/has-own-prop/-/has-own-prop-2.0.0.tgz", "integrity": "sha512-Pq0h+hvsVm6dDEa8x82GnLSYHOzNDt7f0ddFa3FqcQlgzEiptPqL+XrOJNavjOzSYiYWIrgeVYYgGlLmnxwilQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -8561,9 +8526,9 @@ } }, "node_modules/hast-util-raw": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/hast-util-raw/-/hast-util-raw-9.0.1.tgz", - "integrity": "sha512-5m1gmba658Q+lO5uqL5YNGQWeh1MYWZbZmWrM5lncdcuiXuo5E2HT/CIOp0rLF8ksfSwiCVJ3twlgVRyTGThGA==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/hast-util-raw/-/hast-util-raw-9.0.3.tgz", + "integrity": "sha512-ICWvVOF2fq4+7CMmtCPD5CM4QKjPbHpPotE6+8tDooV0ZuyJVUzHsrNX+O5NaRbieTf0F7FfeBOMAwi6Td0+yQ==", "dependencies": { "@types/hast": "^3.0.0", "@types/unist": "^3.0.0", @@ -9072,9 +9037,9 @@ } }, "node_modules/image-size": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.0.2.tgz", - "integrity": "sha512-xfOoWjceHntRb3qFCrh5ZFORYH8XCdYpASltMhZ/Q0KZiOwjdE/Yl2QCiWdwD+lygV5bMCvauzgu5PxBX/Yerg==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz", + "integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==", "dependencies": { "queue": "6.0.2" }, @@ -9082,7 +9047,7 @@ "image-size": "bin/image-size.js" }, "engines": { - "node": ">=14.0.0" + "node": ">=16.x" } }, "node_modules/immer": { @@ -9142,9 +9107,9 @@ } }, "node_modules/import-meta-resolve": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.0.0.tgz", - "integrity": "sha512-okYUR7ZQPH+efeuMJGlq4f8ubUgO50kByRPyt/Cy1Io4PSRsPjxME+YlVaCOx+NIToW7hCsZNFJyTPFFKepRSA==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.1.0.tgz", + "integrity": "sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw==", "dev": true, "funding": { "type": "github", @@ -9390,6 +9355,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -9733,11 +9699,14 @@ } }, "node_modules/lilconfig": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", - "integrity": "sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.1.tgz", + "integrity": "sha512-O18pf7nyvHTckunPWCV1XUNXU1piu01y2b7ATJ0ppkUkk8ocqVWBrYjJBCwHDjD/ZWcfyrA0P4gKhzWGi5EINQ==", "engines": { - "node": ">=10" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antonk52" } }, "node_modules/lines-and-columns": { @@ -10027,9 +9996,9 @@ } }, "node_modules/mdast-util-gfm-autolink-literal/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10259,9 +10228,9 @@ } }, "node_modules/mdn-data": { - "version": "2.0.14", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz", - "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==" + "version": "2.0.30", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", + "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==" }, "node_modules/media-typer": { "version": "0.3.0", @@ -10466,9 +10435,9 @@ } }, "node_modules/micromark-extension-directive/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10515,9 +10484,9 @@ } }, "node_modules/micromark-extension-frontmatter/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10583,9 +10552,9 @@ } }, "node_modules/micromark-extension-gfm-autolink-literal/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10655,9 +10624,9 @@ } }, "node_modules/micromark-extension-gfm-footnote/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10756,9 +10725,9 @@ } }, "node_modules/micromark-extension-gfm-table/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -10837,9 +10806,9 @@ } }, "node_modules/micromark-extension-gfm-task-list-item/node_modules/micromark-util-character": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", - "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.0.tgz", + "integrity": "sha512-KvOVV+X1yLBfs9dCBSopq/+G1PcgT3lAK07mC4BzXi5E7ahzMAF8oIupDDJ6mievI6F+lAATkbQQlQixJfT3aQ==", "funding": [ { "type": "GitHub Sponsors", @@ -11980,11 +11949,12 @@ ] }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -12177,9 +12147,9 @@ } }, "node_modules/node-abi": { - "version": "3.54.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.54.0.tgz", - "integrity": "sha512-p7eGEiQil0YUV3ItH4/tBb781L5impVmmx2E9FRKF7d18XXzp4PGT2tdYMFY6wQqgxD0IwNZOiSJ0/K0fSi/OA==", + "version": "3.63.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.63.0.tgz", + "integrity": "sha512-vAszCsOUrUxjGAmdnM/pq7gUgie0IRteCQMX6d4A534fQCR93EJU5qgzBvU6EkFfK27s0T3HEV3BOyJIr7OMYw==", "dependencies": { "semver": "^7.3.5" }, @@ -12250,17 +12220,6 @@ "node": ">=0.10.0" } }, - "node_modules/normalize-url": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", - "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/npm-normalize-package-bin": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-3.0.1.tgz", @@ -12282,9 +12241,9 @@ } }, "node_modules/npm-to-yarn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/npm-to-yarn/-/npm-to-yarn-2.1.0.tgz", - "integrity": "sha512-2C1IgJLdJngq1bSER7K7CGFszRr9s2rijEwvENPEgI0eK9xlD3tNwDc0UJnRj7FIT2aydWm72jB88uVswAhXHA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/npm-to-yarn/-/npm-to-yarn-2.2.1.tgz", + "integrity": "sha512-O/j/ROyX0KGLG7O6Ieut/seQ0oiTpHF2tXAcFbpdTLQFiaNtkyTXXocM1fwpaa60dg1qpWj0nHlbNhx6qwuENQ==", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -12804,9 +12763,9 @@ } }, "node_modules/postcss": { - "version": "8.4.32", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", - "integrity": "sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==", + "version": "8.4.38", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", + "integrity": "sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==", "funding": [ { "type": "opencollective", @@ -12824,112 +12783,115 @@ "dependencies": { "nanoid": "^3.3.7", "picocolors": "^1.0.0", - "source-map-js": "^1.0.2" + "source-map-js": "^1.2.0" }, "engines": { "node": "^10 || ^12 || >=14" } }, "node_modules/postcss-calc": { - "version": "8.2.4", - "resolved": "https://registry.npmjs.org/postcss-calc/-/postcss-calc-8.2.4.tgz", - "integrity": "sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/postcss-calc/-/postcss-calc-9.0.1.tgz", + "integrity": "sha512-TipgjGyzP5QzEhsOZUaIkeO5mKeMFpebWzRogWG/ysonUlnHcq5aJe0jOjpfzUU8PeSaBQnrE8ehR0QA5vs8PQ==", "dependencies": { - "postcss-selector-parser": "^6.0.9", + "postcss-selector-parser": "^6.0.11", "postcss-value-parser": "^4.2.0" }, + "engines": { + "node": "^14 || ^16 || >=18.0" + }, "peerDependencies": { "postcss": "^8.2.2" } }, "node_modules/postcss-colormin": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/postcss-colormin/-/postcss-colormin-5.3.1.tgz", - "integrity": "sha512-UsWQG0AqTFQmpBegeLLc1+c3jIqBNB0zlDGRWR+dQ3pRKJL1oeMzyqmH3o2PIfn9MBdNrVPWhDbT769LxCTLJQ==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-colormin/-/postcss-colormin-6.1.0.tgz", + "integrity": "sha512-x9yX7DOxeMAR+BgGVnNSAxmAj98NX/YxEMNFP+SDCEeNLb2r3i6Hh1ksMsnW8Ub5SLCpbescQqn9YEbE9554Sw==", "dependencies": { - "browserslist": "^4.21.4", + "browserslist": "^4.23.0", "caniuse-api": "^3.0.0", - "colord": "^2.9.1", + "colord": "^2.9.3", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-convert-values": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/postcss-convert-values/-/postcss-convert-values-5.1.3.tgz", - "integrity": "sha512-82pC1xkJZtcJEfiLw6UXnXVXScgtBrjlO5CBmuDQc+dlb88ZYheFsjTn40+zBVi3DkfF7iezO0nJUPLcJK3pvA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-convert-values/-/postcss-convert-values-6.1.0.tgz", + "integrity": "sha512-zx8IwP/ts9WvUM6NkVSkiU902QZL1bwPhaVaLynPtCsOTqp+ZKbNi+s6XJg3rfqpKGA/oc7Oxk5t8pOQJcwl/w==", "dependencies": { - "browserslist": "^4.21.4", + "browserslist": "^4.23.0", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-discard-comments": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/postcss-discard-comments/-/postcss-discard-comments-5.1.2.tgz", - "integrity": "sha512-+L8208OVbHVF2UQf1iDmRcbdjJkuBF6IS29yBDSiWUIzpYaAhtNl6JYnYm12FnkeCwQqF5LeklOu6rAqgfBZqQ==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-discard-comments/-/postcss-discard-comments-6.0.2.tgz", + "integrity": "sha512-65w/uIqhSBBfQmYnG92FO1mWZjJ4GL5b8atm5Yw2UgrwD7HiNiSSNwJor1eCFGzUgYnN/iIknhNRVqjrrpuglw==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-discard-duplicates": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-discard-duplicates/-/postcss-discard-duplicates-5.1.0.tgz", - "integrity": "sha512-zmX3IoSI2aoenxHV6C7plngHWWhUOV3sP1T8y2ifzxzbtnuhk1EdPwm0S1bIUNaJ2eNbWeGLEwzw8huPD67aQw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-discard-duplicates/-/postcss-discard-duplicates-6.0.3.tgz", + "integrity": "sha512-+JA0DCvc5XvFAxwx6f/e68gQu/7Z9ud584VLmcgto28eB8FqSFZwtrLwB5Kcp70eIoWP/HXqz4wpo8rD8gpsTw==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-discard-empty": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-discard-empty/-/postcss-discard-empty-5.1.1.tgz", - "integrity": "sha512-zPz4WljiSuLWsI0ir4Mcnr4qQQ5e1Ukc3i7UfE2XcrwKK2LIPIqE5jxMRxO6GbI3cv//ztXDsXwEWT3BHOGh3A==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-discard-empty/-/postcss-discard-empty-6.0.3.tgz", + "integrity": "sha512-znyno9cHKQsK6PtxL5D19Fj9uwSzC2mB74cpT66fhgOadEUPyXFkbgwm5tvc3bt3NAy8ltE5MrghxovZRVnOjQ==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-discard-overridden": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-discard-overridden/-/postcss-discard-overridden-5.1.0.tgz", - "integrity": "sha512-21nOL7RqWR1kasIVdKs8HNqQJhFxLsyRfAnUDm4Fe4t4mCWL9OJiHvlHPjcd8zc5Myu89b/7wZDnOSjFgeWRtw==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-discard-overridden/-/postcss-discard-overridden-6.0.2.tgz", + "integrity": "sha512-j87xzI4LUggC5zND7KdjsI25APtyMuynXZSujByMaav2roV6OZX+8AaCUcZSWqckZpjAjRyFDdpqybgjFO0HJQ==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-discard-unused": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-discard-unused/-/postcss-discard-unused-5.1.0.tgz", - "integrity": "sha512-KwLWymI9hbwXmJa0dkrzpRbSJEh0vVUd7r8t0yOGPcfKzyJJxFM8kLyC5Ev9avji6nY95pOp1W6HqIrfT+0VGw==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/postcss-discard-unused/-/postcss-discard-unused-6.0.5.tgz", + "integrity": "sha512-wHalBlRHkaNnNwfC8z+ppX57VhvS+HWgjW508esjdaEYr3Mx7Gnn2xA4R/CKf5+Z9S5qsqC+Uzh4ueENWwCVUA==", "dependencies": { - "postcss-selector-parser": "^6.0.5" + "postcss-selector-parser": "^6.0.16" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-import": { @@ -12969,136 +12931,111 @@ "webpack": "^5.0.0" } }, - "node_modules/postcss-loader/node_modules/cosmiconfig": { - "version": "8.3.6", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", - "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", - "dependencies": { - "import-fresh": "^3.3.0", - "js-yaml": "^4.1.0", - "parse-json": "^5.2.0", - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/d-fischer" - }, - "peerDependencies": { - "typescript": ">=4.9.5" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/postcss-merge-idents": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-merge-idents/-/postcss-merge-idents-5.1.1.tgz", - "integrity": "sha512-pCijL1TREiCoog5nQp7wUe+TUonA2tC2sQ54UGeMmryK3UFGIYKqDyjnqd6RcuI4znFn9hWSLNN8xKE/vWcUQw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-merge-idents/-/postcss-merge-idents-6.0.3.tgz", + "integrity": "sha512-1oIoAsODUs6IHQZkLQGO15uGEbK3EAl5wi9SS8hs45VgsxQfMnxvt+L+zIr7ifZFIH14cfAeVe2uCTa+SPRa3g==", "dependencies": { - "cssnano-utils": "^3.1.0", + "cssnano-utils": "^4.0.2", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-merge-longhand": { - "version": "5.1.7", - "resolved": "https://registry.npmjs.org/postcss-merge-longhand/-/postcss-merge-longhand-5.1.7.tgz", - "integrity": "sha512-YCI9gZB+PLNskrK0BB3/2OzPnGhPkBEwmwhfYk1ilBHYVAZB7/tkTHFBAnCrvBBOmeYyMYw3DMjT55SyxMBzjQ==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/postcss-merge-longhand/-/postcss-merge-longhand-6.0.5.tgz", + "integrity": "sha512-5LOiordeTfi64QhICp07nzzuTDjNSO8g5Ksdibt44d+uvIIAE1oZdRn8y/W5ZtYgRH/lnLDlvi9F8btZcVzu3w==", "dependencies": { "postcss-value-parser": "^4.2.0", - "stylehacks": "^5.1.1" + "stylehacks": "^6.1.1" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-merge-rules": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/postcss-merge-rules/-/postcss-merge-rules-5.1.4.tgz", - "integrity": "sha512-0R2IuYpgU93y9lhVbO/OylTtKMVcHb67zjWIfCiKR9rWL3GUk1677LAqD/BcHizukdZEjT8Ru3oHRoAYoJy44g==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/postcss-merge-rules/-/postcss-merge-rules-6.1.1.tgz", + "integrity": "sha512-KOdWF0gju31AQPZiD+2Ar9Qjowz1LTChSjFFbS+e2sFgc4uHOp3ZvVX4sNeTlk0w2O31ecFGgrFzhO0RSWbWwQ==", "dependencies": { - "browserslist": "^4.21.4", + "browserslist": "^4.23.0", "caniuse-api": "^3.0.0", - "cssnano-utils": "^3.1.0", - "postcss-selector-parser": "^6.0.5" + "cssnano-utils": "^4.0.2", + "postcss-selector-parser": "^6.0.16" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-minify-font-values": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-minify-font-values/-/postcss-minify-font-values-5.1.0.tgz", - "integrity": "sha512-el3mYTgx13ZAPPirSVsHqFzl+BBBDrXvbySvPGFnQcTI4iNslrPaFq4muTkLZmKlGk4gyFAYUBMH30+HurREyA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-minify-font-values/-/postcss-minify-font-values-6.1.0.tgz", + "integrity": "sha512-gklfI/n+9rTh8nYaSJXlCo3nOKqMNkxuGpTn/Qm0gstL3ywTr9/WRKznE+oy6fvfolH6dF+QM4nCo8yPLdvGJg==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-minify-gradients": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-minify-gradients/-/postcss-minify-gradients-5.1.1.tgz", - "integrity": "sha512-VGvXMTpCEo4qHTNSa9A0a3D+dxGFZCYwR6Jokk+/3oB6flu2/PnPXAh2x7x52EkY5xlIHLm+Le8tJxe/7TNhzw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-minify-gradients/-/postcss-minify-gradients-6.0.3.tgz", + "integrity": "sha512-4KXAHrYlzF0Rr7uc4VrfwDJ2ajrtNEpNEuLxFgwkhFZ56/7gaE4Nr49nLsQDZyUe+ds+kEhf+YAUolJiYXF8+Q==", "dependencies": { - "colord": "^2.9.1", - "cssnano-utils": "^3.1.0", + "colord": "^2.9.3", + "cssnano-utils": "^4.0.2", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-minify-params": { - "version": "5.1.4", - "resolved": "https://registry.npmjs.org/postcss-minify-params/-/postcss-minify-params-5.1.4.tgz", - "integrity": "sha512-+mePA3MgdmVmv6g+30rn57USjOGSAyuxUmkfiWpzalZ8aiBkdPYjXWtHuwJGm1v5Ojy0Z0LaSYhHaLJQB0P8Jw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-minify-params/-/postcss-minify-params-6.1.0.tgz", + "integrity": "sha512-bmSKnDtyyE8ujHQK0RQJDIKhQ20Jq1LYiez54WiaOoBtcSuflfK3Nm596LvbtlFcpipMjgClQGyGr7GAs+H1uA==", "dependencies": { - "browserslist": "^4.21.4", - "cssnano-utils": "^3.1.0", + "browserslist": "^4.23.0", + "cssnano-utils": "^4.0.2", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-minify-selectors": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/postcss-minify-selectors/-/postcss-minify-selectors-5.2.1.tgz", - "integrity": "sha512-nPJu7OjZJTsVUmPdm2TcaiohIwxP+v8ha9NehQ2ye9szv4orirRU3SDdtUmKH+10nzn0bAyOXZ0UEr7OpvLehg==", + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/postcss-minify-selectors/-/postcss-minify-selectors-6.0.4.tgz", + "integrity": "sha512-L8dZSwNLgK7pjTto9PzWRoMbnLq5vsZSTu8+j1P/2GB8qdtGQfn+K1uSvFgYvgh83cbyxT5m43ZZhUMTJDSClQ==", "dependencies": { - "postcss-selector-parser": "^6.0.5" + "postcss-selector-parser": "^6.0.16" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-modules-extract-imports": { @@ -13157,192 +13094,191 @@ } }, "node_modules/postcss-normalize-charset": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-normalize-charset/-/postcss-normalize-charset-5.1.0.tgz", - "integrity": "sha512-mSgUJ+pd/ldRGVx26p2wz9dNZ7ji6Pn8VWBajMXFf8jk7vUoSrZ2lt/wZR7DtlZYKesmZI680qjr2CeFF2fbUg==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-charset/-/postcss-normalize-charset-6.0.2.tgz", + "integrity": "sha512-a8N9czmdnrjPHa3DeFlwqst5eaL5W8jYu3EBbTTkI5FHkfMhFZh1EGbku6jhHhIzTA6tquI2P42NtZ59M/H/kQ==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-display-values": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-normalize-display-values/-/postcss-normalize-display-values-5.1.0.tgz", - "integrity": "sha512-WP4KIM4o2dazQXWmFaqMmcvsKmhdINFblgSeRgn8BJ6vxaMyaJkwAzpPpuvSIoG/rmX3M+IrRZEz2H0glrQNEA==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-display-values/-/postcss-normalize-display-values-6.0.2.tgz", + "integrity": "sha512-8H04Mxsb82ON/aAkPeq8kcBbAtI5Q2a64X/mnRRfPXBq7XeogoQvReqxEfc0B4WPq1KimjezNC8flUtC3Qz6jg==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-positions": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-normalize-positions/-/postcss-normalize-positions-5.1.1.tgz", - "integrity": "sha512-6UpCb0G4eofTCQLFVuI3EVNZzBNPiIKcA1AKVka+31fTVySphr3VUgAIULBhxZkKgwLImhzMR2Bw1ORK+37INg==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-positions/-/postcss-normalize-positions-6.0.2.tgz", + "integrity": "sha512-/JFzI441OAB9O7VnLA+RtSNZvQ0NCFZDOtp6QPFo1iIyawyXg0YI3CYM9HBy1WvwCRHnPep/BvI1+dGPKoXx/Q==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-repeat-style": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-normalize-repeat-style/-/postcss-normalize-repeat-style-5.1.1.tgz", - "integrity": "sha512-mFpLspGWkQtBcWIRFLmewo8aC3ImN2i/J3v8YCFUwDnPu3Xz4rLohDO26lGjwNsQxB3YF0KKRwspGzE2JEuS0g==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-repeat-style/-/postcss-normalize-repeat-style-6.0.2.tgz", + "integrity": "sha512-YdCgsfHkJ2jEXwR4RR3Tm/iOxSfdRt7jplS6XRh9Js9PyCR/aka/FCb6TuHT2U8gQubbm/mPmF6L7FY9d79VwQ==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-string": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-normalize-string/-/postcss-normalize-string-5.1.0.tgz", - "integrity": "sha512-oYiIJOf4T9T1N4i+abeIc7Vgm/xPCGih4bZz5Nm0/ARVJ7K6xrDlLwvwqOydvyL3RHNf8qZk6vo3aatiw/go3w==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-string/-/postcss-normalize-string-6.0.2.tgz", + "integrity": "sha512-vQZIivlxlfqqMp4L9PZsFE4YUkWniziKjQWUtsxUiVsSSPelQydwS8Wwcuw0+83ZjPWNTl02oxlIvXsmmG+CiQ==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-timing-functions": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-normalize-timing-functions/-/postcss-normalize-timing-functions-5.1.0.tgz", - "integrity": "sha512-DOEkzJ4SAXv5xkHl0Wa9cZLF3WCBhF3o1SKVxKQAa+0pYKlueTpCgvkFAHfk+Y64ezX9+nITGrDZeVGgITJXjg==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-timing-functions/-/postcss-normalize-timing-functions-6.0.2.tgz", + "integrity": "sha512-a+YrtMox4TBtId/AEwbA03VcJgtyW4dGBizPl7e88cTFULYsprgHWTbfyjSLyHeBcK/Q9JhXkt2ZXiwaVHoMzA==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-unicode": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-normalize-unicode/-/postcss-normalize-unicode-5.1.1.tgz", - "integrity": "sha512-qnCL5jzkNUmKVhZoENp1mJiGNPcsJCs1aaRmURmeJGES23Z/ajaln+EPTD+rBeNkSryI+2WTdW+lwcVdOikrpA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-normalize-unicode/-/postcss-normalize-unicode-6.1.0.tgz", + "integrity": "sha512-QVC5TQHsVj33otj8/JD869Ndr5Xcc/+fwRh4HAsFsAeygQQXm+0PySrKbr/8tkDKzW+EVT3QkqZMfFrGiossDg==", "dependencies": { - "browserslist": "^4.21.4", + "browserslist": "^4.23.0", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-url": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-normalize-url/-/postcss-normalize-url-5.1.0.tgz", - "integrity": "sha512-5upGeDO+PVthOxSmds43ZeMeZfKH+/DKgGRD7TElkkyS46JXAUhMzIKiCa7BabPeIy3AQcTkXwVVN7DbqsiCew==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-url/-/postcss-normalize-url-6.0.2.tgz", + "integrity": "sha512-kVNcWhCeKAzZ8B4pv/DnrU1wNh458zBNp8dh4y5hhxih5RZQ12QWMuQrDgPRw3LRl8mN9vOVfHl7uhvHYMoXsQ==", "dependencies": { - "normalize-url": "^6.0.1", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-normalize-whitespace": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-normalize-whitespace/-/postcss-normalize-whitespace-5.1.1.tgz", - "integrity": "sha512-83ZJ4t3NUDETIHTa3uEg6asWjSBYL5EdkVB0sDncx9ERzOKBVJIUeDO9RyA9Zwtig8El1d79HBp0JEi8wvGQnA==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-normalize-whitespace/-/postcss-normalize-whitespace-6.0.2.tgz", + "integrity": "sha512-sXZ2Nj1icbJOKmdjXVT9pnyHQKiSAyuNQHSgRCUgThn2388Y9cGVDR+E9J9iAYbSbLHI+UUwLVl1Wzco/zgv0Q==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-ordered-values": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/postcss-ordered-values/-/postcss-ordered-values-5.1.3.tgz", - "integrity": "sha512-9UO79VUhPwEkzbb3RNpqqghc6lcYej1aveQteWY+4POIwlqkYE21HKWaLDF6lWNuqCobEAyTovVhtI32Rbv2RQ==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-ordered-values/-/postcss-ordered-values-6.0.2.tgz", + "integrity": "sha512-VRZSOB+JU32RsEAQrO94QPkClGPKJEL/Z9PCBImXMhIeK5KAYo6slP/hBYlLgrCjFxyqvn5VC81tycFEDBLG1Q==", "dependencies": { - "cssnano-utils": "^3.1.0", + "cssnano-utils": "^4.0.2", "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-reduce-idents": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/postcss-reduce-idents/-/postcss-reduce-idents-5.2.0.tgz", - "integrity": "sha512-BTrLjICoSB6gxbc58D5mdBK8OhXRDqud/zodYfdSi52qvDHdMwk+9kB9xsM8yJThH/sZU5A6QVSmMmaN001gIg==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-reduce-idents/-/postcss-reduce-idents-6.0.3.tgz", + "integrity": "sha512-G3yCqZDpsNPoQgbDUy3T0E6hqOQ5xigUtBQyrmq3tn2GxlyiL0yyl7H+T8ulQR6kOcHJ9t7/9H4/R2tv8tJbMA==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-reduce-initial": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/postcss-reduce-initial/-/postcss-reduce-initial-5.1.2.tgz", - "integrity": "sha512-dE/y2XRaqAi6OvjzD22pjTUQ8eOfc6m/natGHgKFBK9DxFmIm69YmaRVQrGgFlEfc1HePIurY0TmDeROK05rIg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-reduce-initial/-/postcss-reduce-initial-6.1.0.tgz", + "integrity": "sha512-RarLgBK/CrL1qZags04oKbVbrrVK2wcxhvta3GCxrZO4zveibqbRPmm2VI8sSgCXwoUHEliRSbOfpR0b/VIoiw==", "dependencies": { - "browserslist": "^4.21.4", + "browserslist": "^4.23.0", "caniuse-api": "^3.0.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-reduce-transforms": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-reduce-transforms/-/postcss-reduce-transforms-5.1.0.tgz", - "integrity": "sha512-2fbdbmgir5AvpW9RLtdONx1QoYG2/EtqpNQbFASDlixBbAYuTcJ0dECwlqNqH7VbaUnEnh8SrxOe2sRIn24XyQ==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-reduce-transforms/-/postcss-reduce-transforms-6.0.2.tgz", + "integrity": "sha512-sB+Ya++3Xj1WaT9+5LOOdirAxP7dJZms3GRcYheSPi1PiTMigsxHAdkrbItHxwYHr4kt1zL7mmcHstgMYT+aiA==", "dependencies": { "postcss-value-parser": "^4.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-selector-parser": { - "version": "6.0.13", - "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.0.13.tgz", - "integrity": "sha512-EaV1Gl4mUEV4ddhDnv/xtj7sxwrwxdetHdWUGnT4VJQf+4d05v6lHYZr8N573k5Z0BViss7BDhfWtKS3+sfAqQ==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.1.0.tgz", + "integrity": "sha512-UMz42UD0UY0EApS0ZL9o1XnLhSTtvvvLe5Dc2H2O56fvRZi+KulDyf5ctDhhtYJBGKStV2FL1fy6253cmLgqVQ==", "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -13352,46 +13288,46 @@ } }, "node_modules/postcss-sort-media-queries": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/postcss-sort-media-queries/-/postcss-sort-media-queries-4.4.1.tgz", - "integrity": "sha512-QDESFzDDGKgpiIh4GYXsSy6sek2yAwQx1JASl5AxBtU1Lq2JfKBljIPNdil989NcSKRQX1ToiaKphImtBuhXWw==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/postcss-sort-media-queries/-/postcss-sort-media-queries-5.2.0.tgz", + "integrity": "sha512-AZ5fDMLD8SldlAYlvi8NIqo0+Z8xnXU2ia0jxmuhxAU+Lqt9K+AlmLNJ/zWEnE9x+Zx3qL3+1K20ATgNOr3fAA==", "dependencies": { - "sort-css-media-queries": "2.1.0" + "sort-css-media-queries": "2.2.0" }, "engines": { - "node": ">=10.0.0" + "node": ">=14.0.0" }, "peerDependencies": { - "postcss": "^8.4.16" + "postcss": "^8.4.23" } }, "node_modules/postcss-svgo": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-5.1.0.tgz", - "integrity": "sha512-D75KsH1zm5ZrHyxPakAxJWtkyXew5qwS70v56exwvw542d9CRtTo78K0WeFxZB4G7JXKKMbEZtZayTGdIky/eA==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-6.0.3.tgz", + "integrity": "sha512-dlrahRmxP22bX6iKEjOM+c8/1p+81asjKT+V5lrgOH944ryx/OHpclnIbGsKVd3uWOXFLYJwCVf0eEkJGvO96g==", "dependencies": { "postcss-value-parser": "^4.2.0", - "svgo": "^2.7.0" + "svgo": "^3.2.0" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >= 18" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-unique-selectors": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/postcss-unique-selectors/-/postcss-unique-selectors-5.1.1.tgz", - "integrity": "sha512-5JiODlELrz8L2HwxfPnhOWZYWDxVHWL83ufOv84NrcgipI7TaeRsatAhK4Tr2/ZiYldpK/wBvw5BD3qfaK96GA==", + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/postcss-unique-selectors/-/postcss-unique-selectors-6.0.4.tgz", + "integrity": "sha512-K38OCaIrO8+PzpArzkLKB42dSARtC2tmG6PvD4b1o1Q2E9Os8jzfWFfSy/rixsHwohtsDdFtAWGjFVFUdwYaMg==", "dependencies": { - "postcss-selector-parser": "^6.0.5" + "postcss-selector-parser": "^6.0.16" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/postcss-value-parser": { @@ -13400,20 +13336,20 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, "node_modules/postcss-zindex": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/postcss-zindex/-/postcss-zindex-5.1.0.tgz", - "integrity": "sha512-fgFMf0OtVSBR1va1JNHYgMxYk73yhn/qb4uQDq1DLGYolz8gHCyr/sesEuGUaYs58E3ZJRcpoGuPVoB7Meiq9A==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/postcss-zindex/-/postcss-zindex-6.0.2.tgz", + "integrity": "sha512-5BxW9l1evPB/4ZIc+2GobEBoKC+h8gPGCMi+jxsYvd2x0mjq7wazk6DrP71pStqxE9Foxh5TVnonbWpFZzXaYg==", "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/prebuild-install": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz", - "integrity": "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.2.tgz", + "integrity": "sha512-UnNke3IQb6sgarcZIDU3gbMeTp/9SSU1DAIkil7PrqG1vZlBtY5msYccSKSHDqa3hNg436IXK+SNImReuA1wEQ==", "dependencies": { "detect-libc": "^2.0.0", "expand-template": "^2.0.3", @@ -13462,10 +13398,11 @@ } }, "node_modules/prettier": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", - "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz", + "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, @@ -13934,9 +13871,9 @@ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, "node_modules/react-json-view-lite": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/react-json-view-lite/-/react-json-view-lite-1.2.1.tgz", - "integrity": "sha512-Itc0g86fytOmKZoIoJyGgvNqohWSbh3NXIKNgH6W6FT9PC1ck4xas1tT3Rr/b3UlFXyA9Jjaw9QSXdZy2JwGMQ==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/react-json-view-lite/-/react-json-view-lite-1.4.0.tgz", + "integrity": "sha512-wh6F6uJyYAmQ4fK0e8dSQMEWuvTs2Wr3el3sLD9bambX1+pSWUVXIz1RFaoy3TI1mZ0FqdpKq9YgbgTTgyrmXA==", "engines": { "node": ">=14" }, @@ -13946,12 +13883,11 @@ }, "node_modules/react-loadable": { "name": "@docusaurus/react-loadable", - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/@docusaurus/react-loadable/-/react-loadable-5.5.2.tgz", - "integrity": "sha512-A3dYjdBGuy0IGT+wyLIGIKLRE+sAk1iNk0f1HjNDysO7u8lhL4N3VEm+FAubmJbAztn94F7MxBTPmnixbiyFdQ==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@docusaurus/react-loadable/-/react-loadable-6.0.0.tgz", + "integrity": "sha512-YMMxTUQV/QFSnbgrP3tjDzLHRg7vsbMn8e9HAa8o/1iXoiomo48b7sk/kkmWEuWNDPJVlKSJRB6Y2fHqdJk+SQ==", "dependencies": { - "@types/react": "*", - "prop-types": "^15.6.2" + "@types/react": "*" }, "peerDependencies": { "react": "*" @@ -14035,9 +13971,9 @@ } }, "node_modules/react-waypoint/node_modules/react-is": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", - "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", + "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==" }, "node_modules/read-cache": { "version": "1.0.0", @@ -14248,12 +14184,12 @@ } }, "node_modules/remark-cli": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/remark-cli/-/remark-cli-12.0.0.tgz", - "integrity": "sha512-IGxCo2VsXC/GS2YdlF7+S8DsUiyULyiauik01NFoiMIrOlbDhXjrKLD8hYazwQdD67nw2k7cwOBIxcK/cbNd9Q==", + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/remark-cli/-/remark-cli-12.0.1.tgz", + "integrity": "sha512-2NAEOACoTgo+e+YAaCTODqbrWyhMVmlUyjxNCkTrDRHHQvH6+NbrnqVvQaLH/Q8Ket3v90A43dgAJmXv8y5Tkw==", "dev": true, "dependencies": { - "import-meta-resolve": "^3.0.0", + "import-meta-resolve": "^4.0.0", "markdown-extensions": "^2.0.0", "remark": "^15.0.0", "unified-args": "^11.0.0" @@ -14266,16 +14202,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-cli/node_modules/import-meta-resolve": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-3.1.1.tgz", - "integrity": "sha512-qeywsE/KC3w9Fd2ORrRDUw6nS/nLwZpXgfrOc2IILvZYnCaEMd+D56Vfg9k4G29gIeVi3XKql1RQatME8iYsiw==", - "dev": true, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/remark-directive": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/remark-directive/-/remark-directive-3.0.0.tgz", @@ -14542,6 +14468,7 @@ "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10" } @@ -14813,9 +14740,9 @@ } }, "node_modules/sax": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.3.0.tgz", - "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==" + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" }, "node_modules/scheduler": { "version": "0.23.0", @@ -14844,9 +14771,9 @@ } }, "node_modules/search-insights": { - "version": "2.13.0", - "resolved": "https://registry.npmjs.org/search-insights/-/search-insights-2.13.0.tgz", - "integrity": "sha512-Orrsjf9trHHxFRuo9/rzm0KIWmgzE8RMlZMzuhZOJ01Rnz3D0YBAe+V6473t6/H6c7irs6Lt48brULAiRWb3Vw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/search-insights/-/search-insights-2.14.0.tgz", + "integrity": "sha512-OLN6MsPMCghDOqlCtsIsYgtsC0pnwVTyT9Mu6A3ewOj1DxvzZF6COrn2g86E/c05xbktB0XN04m/t1Z+n+fTGw==", "peer": true }, "node_modules/section-matter": { @@ -14879,12 +14806,9 @@ } }, "node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dependencies": { - "lru-cache": "^6.0.0" - }, + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", "bin": { "semver": "bin/semver.js" }, @@ -14906,22 +14830,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/semver/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/semver/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" - }, "node_modules/send": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", @@ -15282,9 +15190,9 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" }, "node_modules/sitemap": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-7.1.1.tgz", - "integrity": "sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-7.1.2.tgz", + "integrity": "sha512-ARCqzHJ0p4gWt+j7NlU5eDlIO9+Rkr/JhPFZKKQ1l5GCus7rJH4UdrlVAh0xC/gDS/Qir2UMxqYNHtsKr2rpCw==", "dependencies": { "@types/node": "^17.0.5", "@types/sax": "^1.2.1", @@ -15331,6 +15239,15 @@ "node": ">=8.0.0" } }, + "node_modules/snake-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/snake-case/-/snake-case-3.0.4.tgz", + "integrity": "sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==", + "dependencies": { + "dot-case": "^3.0.4", + "tslib": "^2.0.3" + } + }, "node_modules/sockjs": { "version": "0.3.24", "resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.24.tgz", @@ -15342,9 +15259,9 @@ } }, "node_modules/sort-css-media-queries": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/sort-css-media-queries/-/sort-css-media-queries-2.1.0.tgz", - "integrity": "sha512-IeWvo8NkNiY2vVYdPa27MCQiR0MN0M80johAYFVxWWXQ44KU84WNxjslwBHmc/7ZL2ccwkM7/e6S5aiKZXm7jA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/sort-css-media-queries/-/sort-css-media-queries-2.2.0.tgz", + "integrity": "sha512-0xtkGhWCC9MGt/EzgnvbbbKhqWjl1+/rncmhTh5qCpbYguXh6S/qwePfv/JQ8jePXXmqingylxoC49pCkSPIbA==", "engines": { "node": ">= 6.3.0" } @@ -15358,9 +15275,9 @@ } }, "node_modules/source-map-js": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", - "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", + "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==", "engines": { "node": ">=0.10.0" } @@ -15435,12 +15352,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/stable": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.8.tgz", - "integrity": "sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w==", - "deprecated": "Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility" - }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -15455,12 +15366,16 @@ "integrity": "sha512-aFZ19IgVmhdB2uX599ve2kE6BIE3YMnQ6Gp6BURhW/oIzpXGKr878TQfAQZn1+i0Flcc/UKUy1gOlcfaUBCryg==" }, "node_modules/streamx": { - "version": "2.15.6", - "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.6.tgz", - "integrity": "sha512-q+vQL4AAz+FdfT137VF69Cc/APqUbxy+MDOImRrMvchJpigHj9GksgDU2LYbO9rx7RX6osWgxJB2WxhYv4SZAw==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.18.0.tgz", + "integrity": "sha512-LLUC1TWdjVdn1weXGcSxyTR3T4+acB6tVGXT95y0nGbca4t4o/ng1wKAGTljm9VicuCVLvRlqFYXYy5GwgM7sQ==", "dependencies": { - "fast-fifo": "^1.1.0", - "queue-tick": "^1.0.1" + "fast-fifo": "^1.3.2", + "queue-tick": "^1.0.1", + "text-decoder": "^1.1.0" + }, + "optionalDependencies": { + "bare-events": "^2.2.0" } }, "node_modules/string_decoder": { @@ -15635,18 +15550,18 @@ } }, "node_modules/stylehacks": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-5.1.1.tgz", - "integrity": "sha512-sBpcd5Hx7G6seo7b1LkpttvTz7ikD0LlH5RmdcBNb6fFR0Fl7LQwHDFr300q4cwUqi+IYrFGmsIHieMBfnN/Bw==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-6.1.1.tgz", + "integrity": "sha512-gSTTEQ670cJNoaeIp9KX6lZmm8LJ3jPB5yJmX8Zq/wQxOsAFXV3qjWzHas3YYk1qesuVIyYWWUpZ0vSE/dTSGg==", "dependencies": { - "browserslist": "^4.21.4", - "postcss-selector-parser": "^6.0.4" + "browserslist": "^4.23.0", + "postcss-selector-parser": "^6.0.16" }, "engines": { - "node": "^10 || ^12 || >=14.0" + "node": "^14 || ^16 || >=18.0" }, "peerDependencies": { - "postcss": "^8.2.15" + "postcss": "^8.4.31" } }, "node_modules/supports-color": { @@ -15677,23 +15592,27 @@ "integrity": "sha512-e4hG1hRwoOdRb37cIMSgzNsxyzKfayW6VOflrwvR+/bzrkyxY/31WkbgnQpgtrNp1SdpJvpUAGTa/ZoiPNDuRQ==" }, "node_modules/svgo": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/svgo/-/svgo-2.8.0.tgz", - "integrity": "sha512-+N/Q9kV1+F+UeWYoSiULYo4xYSDQlTgb+ayMobAXPwMnLvop7oxKMo9OzIrX5x3eS4L4f2UHhc9axXwY8DpChg==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/svgo/-/svgo-3.3.2.tgz", + "integrity": "sha512-OoohrmuUlBs8B8o6MB2Aevn+pRIH9zDALSR+6hhqVfa6fRwG/Qw9VUMSMW9VNg2CFc/MTIfabtdOVl9ODIJjpw==", "dependencies": { "@trysound/sax": "0.2.0", "commander": "^7.2.0", - "css-select": "^4.1.3", - "css-tree": "^1.1.3", - "csso": "^4.2.0", - "picocolors": "^1.0.0", - "stable": "^0.1.8" + "css-select": "^5.1.0", + "css-tree": "^2.3.1", + "css-what": "^6.1.0", + "csso": "^5.0.5", + "picocolors": "^1.0.0" }, "bin": { "svgo": "bin/svgo" }, "engines": { - "node": ">=10.13.0" + "node": ">=14.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/svgo" } }, "node_modules/svgo/node_modules/commander": { @@ -15704,69 +15623,6 @@ "node": ">= 10" } }, - "node_modules/svgo/node_modules/css-select": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz", - "integrity": "sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ==", - "dependencies": { - "boolbase": "^1.0.0", - "css-what": "^6.0.1", - "domhandler": "^4.3.1", - "domutils": "^2.8.0", - "nth-check": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/svgo/node_modules/dom-serializer": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.4.1.tgz", - "integrity": "sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==", - "dependencies": { - "domelementtype": "^2.0.1", - "domhandler": "^4.2.0", - "entities": "^2.0.0" - }, - "funding": { - "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" - } - }, - "node_modules/svgo/node_modules/domhandler": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.3.1.tgz", - "integrity": "sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ==", - "dependencies": { - "domelementtype": "^2.2.0" - }, - "engines": { - "node": ">= 4" - }, - "funding": { - "url": "https://github.com/fb55/domhandler?sponsor=1" - } - }, - "node_modules/svgo/node_modules/domutils": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz", - "integrity": "sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==", - "dependencies": { - "dom-serializer": "^1.0.1", - "domelementtype": "^2.2.0", - "domhandler": "^4.2.0" - }, - "funding": { - "url": "https://github.com/fb55/domutils?sponsor=1" - } - }, - "node_modules/svgo/node_modules/entities": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz", - "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==", - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, "node_modules/tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -15776,19 +15632,22 @@ } }, "node_modules/tar-fs": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.4.tgz", - "integrity": "sha512-5AFQU8b9qLfZCX9zp2duONhPmZv0hGYiBPJsyUdqMjzq/mqVpy/rEUSeHk1+YitmxugaptgBh5oDGU3VsAJq4w==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.0.6.tgz", + "integrity": "sha512-iokBDQQkUyeXhgPYaZxmczGPhnhXZ0CmrqI+MOb/WFGS9DW5wnfrLgtjUJBvz50vQ3qfRwJ62QVoCFu8mPVu5w==", "dependencies": { - "mkdirp-classic": "^0.5.2", "pump": "^3.0.0", "tar-stream": "^3.1.5" + }, + "optionalDependencies": { + "bare-fs": "^2.1.1", + "bare-path": "^2.1.0" } }, "node_modules/tar-stream": { - "version": "3.1.6", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.6.tgz", - "integrity": "sha512-B/UyjYwPpMBv+PaFSWAmtYjwdrlEaZQEhMIBFNC5oEG8lpiW8XjcSdmEaClj28ArfKScKHs2nshz3k2le6crsg==", + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-3.1.7.tgz", + "integrity": "sha512-qJj60CXt7IU1Ffyc3NJMjh6EkuCFej46zUqJ4J7pqYlThyd9bO0XBTmcOIhSzZJVWfsLks0+nle/j538YAW9RQ==", "dependencies": { "b4a": "^1.6.4", "fast-fifo": "^1.2.0", @@ -15922,6 +15781,14 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, + "node_modules/text-decoder": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/text-decoder/-/text-decoder-1.1.0.tgz", + "integrity": "sha512-TmLJNj6UgX8xcUZo4UDStGQtDiTzF7BzWlzn9g7UWrjkpHr5uJTK1ld16wZ3LXb2vb6jH8qU89dW5whuMdXYdw==", + "dependencies": { + "b4a": "^1.6.4" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -15954,6 +15821,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, diff --git a/package.json b/package.json index 04b1450b8..8e34ea2f2 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "prettier.dry-run": "npm run prettier.base -- --list-different" }, "dependencies": { - "@docusaurus/core": "^3.1.1", - "@docusaurus/remark-plugin-npm2yarn": "^3.1.1", - "@ionic-docs/preset-classic": "^1.1.0", + "@docusaurus/core": "^3.4.0", + "@docusaurus/remark-plugin-npm2yarn": "^3.4.0", + "@ionic-docs/preset-classic": "^1.2.7", "clsx": "^2.0.0", "docusaurus-theme-github-codeblock": "^2.0.2", "prism-react-renderer": "^2.3.0", @@ -29,7 +29,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "^3.1.1", + "@docusaurus/module-type-aliases": "^3.4.0", "@ionic/prettier-config": "^4.0.0", "cspell": "^8.0.0", "prettier": "^3.2.2", @@ -50,7 +50,7 @@ }, "prettier": "@ionic/prettier-config", "volta": { - "node": "20.12.2", - "npm": "10.5.2" + "node": "20.15.1", + "npm": "10.8.2" } } diff --git a/renovate.json5 b/renovate.json5 index f621bd87b..682cca813 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -47,8 +47,12 @@ ], // Never rebase the branch or update it unless manually requested to avoid noisy PR emails rebaseWhen: 'never', - // Note: Timezone for the schedule is specified as UTC - schedule: ['every weekday before 11am'], + /** + * Cron syntax to run at midnight (UTC) on the first day of every month + * + * Note: Renovate does not support minute value granularity, so the wildcard value is necessary + */ + schedule: ['* 0 1 * *'], /** * Ensure semantic commits are enabled for commits + PR titles. * diff --git a/src/css/custom.scss b/src/css/custom.scss index 0aa86a429..88513c98c 100644 --- a/src/css/custom.scss +++ b/src/css/custom.scss @@ -24,4 +24,46 @@ --search-border: var(--c-carbon-80); } + + // OS Announcement Bar + :root { + --docusaurus-announcement-bar-height: 3.5rem; + } + [class*='announcementBar_'] { + background: linear-gradient(90deg, #440f14, #5e1219 15%, #000 35%, #000 45%, #5e1219 85%, #440f14); + + &:hover, + &:focus, + &:active { + strong { + color: var(--c-red-50); + } + } + } + [class*='announcementBarContent_'] { + padding: 0; + + > a { + display: flex; + align-items: center; + justify-content: center; + height: var(--docusaurus-announcement-bar-height); + + letter-spacing: 0.01em; + text-decoration: none; + + color: #fff; + + font-size: 1rem; + font-weight: 500; + + strong { + font-weight: 500; + + color: var(--c-red-70); + + transition: color 0.2s ease-out; + } + } + } } diff --git a/versioned_docs/version-v3/components/component-lifecycle.md b/versioned_docs/version-v3/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v3/components/component-lifecycle.md +++ b/versioned_docs/version-v3/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v3/config/01-overview.md b/versioned_docs/version-v3/config/01-overview.md index 41fb5ec97..daee40002 100644 --- a/versioned_docs/version-v3/config/01-overview.md +++ b/versioned_docs/version-v3/config/01-overview.md @@ -83,6 +83,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v3/config/plugins.md b/versioned_docs/version-v3/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v3/config/plugins.md +++ b/versioned_docs/version-v3/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v3/testing/e2e-testing.md b/versioned_docs/version-v3/testing/e2e-testing.md index f8825b3cf..730ec16da 100644 --- a/versioned_docs/version-v3/testing/e2e-testing.md +++ b/versioned_docs/version-v3/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript diff --git a/versioned_docs/version-v4.0/components/api.md b/versioned_docs/version-v4.0/components/api.md index 9fb441c87..617073f8b 100644 --- a/versioned_docs/version-v4.0/components/api.md +++ b/versioned_docs/version-v4.0/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.0/components/component-lifecycle.md b/versioned_docs/version-v4.0/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.0/components/component-lifecycle.md +++ b/versioned_docs/version-v4.0/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.0/config/01-overview.md b/versioned_docs/version-v4.0/config/01-overview.md index a12e46783..a9dcef5d9 100644 --- a/versioned_docs/version-v4.0/config/01-overview.md +++ b/versioned_docs/version-v4.0/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.0/config/plugins.md b/versioned_docs/version-v4.0/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.0/config/plugins.md +++ b/versioned_docs/version-v4.0/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.0/framework-integration/angular.md b/versioned_docs/version-v4.0/framework-integration/angular.md index 380a557a5..d3690aea4 100644 --- a/versioned_docs/version-v4.0/framework-integration/angular.md +++ b/versioned_docs/version-v4.0/framework-integration/angular.md @@ -293,6 +293,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + Now you can reference your component library as a standard import. If you distributed your components through a primary `NgModule`, you can simply import that module into an implementation to use your components. diff --git a/versioned_docs/version-v4.0/guides/assets.md b/versioned_docs/version-v4.0/guides/assets.md index c709d4492..8a1c2e1b1 100644 --- a/versioned_docs/version-v4.0/guides/assets.md +++ b/versioned_docs/version-v4.0/guides/assets.md @@ -62,6 +62,8 @@ When using `getAssetPath`, the assets in the directory structure above are resol The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments. The return value is a path that Stencil has built to retrieve the asset on the filesystem. ```ts +import { getAssetPath } from '@stencil/core'; + // with an asset base path of "/build/": // '/build/assets/logo.png' @@ -209,7 +211,10 @@ declare function getAssetPath(path: string): string; ``` The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments, when an asset base path of `/build/` has been set. + ```ts +import { getAssetPath } from '@stencil/core'; + // with an asset base path of "/build/": // "/build/" getAssetPath(''); @@ -227,7 +232,7 @@ getAssetPath('/assets/my-image.png'); ### setAssetPath -`setAssetPath` is an API provided by Stencil to manually set the asset base path where assets can be found. +`setAssetPath` is an API provided by Stencil's runtime to manually set the asset base path where assets can be found. If you are using `getAssetPath` to compose the path for your component assets, `setAssetPath` allows you or the consumer of the component to change that path. ```ts /** @@ -238,13 +243,43 @@ getAssetPath('/assets/my-image.png'); export declare function setAssetPath(path: string): string; ``` -Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. -As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects -when using a component. +Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects when using a component. + +Make sure as component author to export this function as part of your module in order to also make it accessible to the consumer of your component, e.g. in your package entry file export the function via: + +```ts title="/src/index.ts" +export { setAssetPath } from '@stencil/core'; +``` + +Now your users can import it directly from your component library, e.g.: -If the file calling `setAssetPath` is a module, it's recommended to use `import.meta.url`. +```ts +import { setAssetPath } from 'my-component-library'; +setAssetPath(`${window.location.protocol}//assets.${window.location.host}/`); +``` + +Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the +asset base path. This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. + +:::note + +If your component library exports components compiled with [`dist-output-target`](/output-targets/custom-elements.md) and `externalRuntime` set to `true`, then `setAssetPath` has to be imported from `@stencil/core` directly. + +::: -Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) -when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the -asset base path. -This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. +In case you import a component directly via script tag, this would look like: + +```html + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.0/output-targets/copy-tasks.md b/versioned_docs/version-v4.0/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.0/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.0/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.0/testing/e2e-testing.md b/versioned_docs/version-v4.0/testing/e2e-testing.md index f8825b3cf..730ec16da 100644 --- a/versioned_docs/version-v4.0/testing/e2e-testing.md +++ b/versioned_docs/version-v4.0/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript diff --git a/versioned_docs/version-v4.1/components/api.md b/versioned_docs/version-v4.1/components/api.md index 9fb441c87..617073f8b 100644 --- a/versioned_docs/version-v4.1/components/api.md +++ b/versioned_docs/version-v4.1/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.1/components/component-lifecycle.md b/versioned_docs/version-v4.1/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.1/components/component-lifecycle.md +++ b/versioned_docs/version-v4.1/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.1/config/01-overview.md b/versioned_docs/version-v4.1/config/01-overview.md index a12e46783..a9dcef5d9 100644 --- a/versioned_docs/version-v4.1/config/01-overview.md +++ b/versioned_docs/version-v4.1/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.1/config/plugins.md b/versioned_docs/version-v4.1/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.1/config/plugins.md +++ b/versioned_docs/version-v4.1/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.1/framework-integration/angular.md b/versioned_docs/version-v4.1/framework-integration/angular.md index ff3627132..e16af6251 100644 --- a/versioned_docs/version-v4.1/framework-integration/angular.md +++ b/versioned_docs/version-v4.1/framework-integration/angular.md @@ -288,6 +288,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + Now you can reference your component library as a standard import. If you distributed your components through a primary `NgModule`, you can simply import that module into an implementation to use your components. diff --git a/versioned_docs/version-v4.1/guides/assets.md b/versioned_docs/version-v4.1/guides/assets.md index c709d4492..8a1c2e1b1 100644 --- a/versioned_docs/version-v4.1/guides/assets.md +++ b/versioned_docs/version-v4.1/guides/assets.md @@ -62,6 +62,8 @@ When using `getAssetPath`, the assets in the directory structure above are resol The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments. The return value is a path that Stencil has built to retrieve the asset on the filesystem. ```ts +import { getAssetPath } from '@stencil/core'; + // with an asset base path of "/build/": // '/build/assets/logo.png' @@ -209,7 +211,10 @@ declare function getAssetPath(path: string): string; ``` The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments, when an asset base path of `/build/` has been set. + ```ts +import { getAssetPath } from '@stencil/core'; + // with an asset base path of "/build/": // "/build/" getAssetPath(''); @@ -227,7 +232,7 @@ getAssetPath('/assets/my-image.png'); ### setAssetPath -`setAssetPath` is an API provided by Stencil to manually set the asset base path where assets can be found. +`setAssetPath` is an API provided by Stencil's runtime to manually set the asset base path where assets can be found. If you are using `getAssetPath` to compose the path for your component assets, `setAssetPath` allows you or the consumer of the component to change that path. ```ts /** @@ -238,13 +243,43 @@ getAssetPath('/assets/my-image.png'); export declare function setAssetPath(path: string): string; ``` -Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. -As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects -when using a component. +Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects when using a component. + +Make sure as component author to export this function as part of your module in order to also make it accessible to the consumer of your component, e.g. in your package entry file export the function via: + +```ts title="/src/index.ts" +export { setAssetPath } from '@stencil/core'; +``` + +Now your users can import it directly from your component library, e.g.: -If the file calling `setAssetPath` is a module, it's recommended to use `import.meta.url`. +```ts +import { setAssetPath } from 'my-component-library'; +setAssetPath(`${window.location.protocol}//assets.${window.location.host}/`); +``` + +Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the +asset base path. This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. + +:::note + +If your component library exports components compiled with [`dist-output-target`](/output-targets/custom-elements.md) and `externalRuntime` set to `true`, then `setAssetPath` has to be imported from `@stencil/core` directly. + +::: -Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) -when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the -asset base path. -This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. +In case you import a component directly via script tag, this would look like: + +```html + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.1/output-targets/copy-tasks.md b/versioned_docs/version-v4.1/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.1/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.1/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.1/testing/e2e-testing.md b/versioned_docs/version-v4.1/testing/e2e-testing.md index f8825b3cf..730ec16da 100644 --- a/versioned_docs/version-v4.1/testing/e2e-testing.md +++ b/versioned_docs/version-v4.1/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript diff --git a/versioned_docs/version-v4.10/components/api.md b/versioned_docs/version-v4.10/components/api.md index 9fb441c87..617073f8b 100644 --- a/versioned_docs/version-v4.10/components/api.md +++ b/versioned_docs/version-v4.10/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.10/components/component-lifecycle.md b/versioned_docs/version-v4.10/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.10/components/component-lifecycle.md +++ b/versioned_docs/version-v4.10/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.10/config/01-overview.md b/versioned_docs/version-v4.10/config/01-overview.md index a12e46783..a9dcef5d9 100644 --- a/versioned_docs/version-v4.10/config/01-overview.md +++ b/versioned_docs/version-v4.10/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.10/config/plugins.md b/versioned_docs/version-v4.10/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.10/config/plugins.md +++ b/versioned_docs/version-v4.10/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.10/framework-integration/angular.md b/versioned_docs/version-v4.10/framework-integration/angular.md index e63721bc2..8369e6809 100644 --- a/versioned_docs/version-v4.10/framework-integration/angular.md +++ b/versioned_docs/version-v4.10/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.10/output-targets/copy-tasks.md b/versioned_docs/version-v4.10/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.10/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.10/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.10/testing/e2e-testing.md b/versioned_docs/version-v4.10/testing/e2e-testing.md index f8825b3cf..730ec16da 100644 --- a/versioned_docs/version-v4.10/testing/e2e-testing.md +++ b/versioned_docs/version-v4.10/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript diff --git a/versioned_docs/version-v4.11/components/api.md b/versioned_docs/version-v4.11/components/api.md index 9fb441c87..617073f8b 100644 --- a/versioned_docs/version-v4.11/components/api.md +++ b/versioned_docs/version-v4.11/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.11/components/component-lifecycle.md b/versioned_docs/version-v4.11/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.11/components/component-lifecycle.md +++ b/versioned_docs/version-v4.11/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.11/config/01-overview.md b/versioned_docs/version-v4.11/config/01-overview.md index a12e46783..a9dcef5d9 100644 --- a/versioned_docs/version-v4.11/config/01-overview.md +++ b/versioned_docs/version-v4.11/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.11/config/plugins.md b/versioned_docs/version-v4.11/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.11/config/plugins.md +++ b/versioned_docs/version-v4.11/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.11/framework-integration/angular.md b/versioned_docs/version-v4.11/framework-integration/angular.md index e63721bc2..8369e6809 100644 --- a/versioned_docs/version-v4.11/framework-integration/angular.md +++ b/versioned_docs/version-v4.11/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.11/output-targets/copy-tasks.md b/versioned_docs/version-v4.11/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.11/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.11/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.11/testing/e2e-testing.md b/versioned_docs/version-v4.11/testing/e2e-testing.md index f8825b3cf..730ec16da 100644 --- a/versioned_docs/version-v4.11/testing/e2e-testing.md +++ b/versioned_docs/version-v4.11/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript diff --git a/versioned_docs/version-v4.12/components/api.md b/versioned_docs/version-v4.12/components/api.md index d49a41f94..4b2fe48f8 100644 --- a/versioned_docs/version-v4.12/components/api.md +++ b/versioned_docs/version-v4.12/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.12/components/component-lifecycle.md b/versioned_docs/version-v4.12/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.12/components/component-lifecycle.md +++ b/versioned_docs/version-v4.12/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.12/config/01-overview.md b/versioned_docs/version-v4.12/config/01-overview.md index a12e46783..a9dcef5d9 100644 --- a/versioned_docs/version-v4.12/config/01-overview.md +++ b/versioned_docs/version-v4.12/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.12/config/plugins.md b/versioned_docs/version-v4.12/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.12/config/plugins.md +++ b/versioned_docs/version-v4.12/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.12/framework-integration/angular.md b/versioned_docs/version-v4.12/framework-integration/angular.md index e63721bc2..8369e6809 100644 --- a/versioned_docs/version-v4.12/framework-integration/angular.md +++ b/versioned_docs/version-v4.12/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.12/output-targets/copy-tasks.md b/versioned_docs/version-v4.12/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.12/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.12/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.12/testing/e2e-testing.md b/versioned_docs/version-v4.12/testing/e2e-testing.md index f8825b3cf..908a58937 100644 --- a/versioned_docs/version-v4.12/testing/e2e-testing.md +++ b/versioned_docs/version-v4.12/testing/e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -232,6 +242,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.13.0/components/api.md b/versioned_docs/version-v4.13.0/components/api.md index 174f446d2..6051e207b 100644 --- a/versioned_docs/version-v4.13.0/components/api.md +++ b/versioned_docs/version-v4.13.0/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.13.0/components/component-lifecycle.md b/versioned_docs/version-v4.13.0/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.13.0/components/component-lifecycle.md +++ b/versioned_docs/version-v4.13.0/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.13.0/config/01-overview.md b/versioned_docs/version-v4.13.0/config/01-overview.md index 8d35ca59b..c800d076e 100644 --- a/versioned_docs/version-v4.13.0/config/01-overview.md +++ b/versioned_docs/version-v4.13.0/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.13.0/config/plugins.md b/versioned_docs/version-v4.13.0/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.13.0/config/plugins.md +++ b/versioned_docs/version-v4.13.0/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.13.0/framework-integration/angular.md b/versioned_docs/version-v4.13.0/framework-integration/angular.md index e608d0438..689ab7a12 100644 --- a/versioned_docs/version-v4.13.0/framework-integration/angular.md +++ b/versioned_docs/version-v4.13.0/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.13.0/output-targets/copy-tasks.md b/versioned_docs/version-v4.13.0/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.13.0/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.13.0/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.13.0/testing/stencil-testrunner/05-e2e-testing.md b/versioned_docs/version-v4.13.0/testing/stencil-testrunner/05-e2e-testing.md index b5c0f1897..862b690f8 100644 --- a/versioned_docs/version-v4.13.0/testing/stencil-testrunner/05-e2e-testing.md +++ b/versioned_docs/version-v4.13.0/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -219,6 +229,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.14/components/api.md b/versioned_docs/version-v4.14/components/api.md index 174f446d2..6051e207b 100644 --- a/versioned_docs/version-v4.14/components/api.md +++ b/versioned_docs/version-v4.14/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.14/components/component-lifecycle.md b/versioned_docs/version-v4.14/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.14/components/component-lifecycle.md +++ b/versioned_docs/version-v4.14/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.14/config/01-overview.md b/versioned_docs/version-v4.14/config/01-overview.md index 8d35ca59b..c800d076e 100644 --- a/versioned_docs/version-v4.14/config/01-overview.md +++ b/versioned_docs/version-v4.14/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.14/config/plugins.md b/versioned_docs/version-v4.14/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.14/config/plugins.md +++ b/versioned_docs/version-v4.14/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.14/framework-integration/angular.md b/versioned_docs/version-v4.14/framework-integration/angular.md index e608d0438..689ab7a12 100644 --- a/versioned_docs/version-v4.14/framework-integration/angular.md +++ b/versioned_docs/version-v4.14/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.14/output-targets/copy-tasks.md b/versioned_docs/version-v4.14/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.14/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.14/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.14/testing/stencil-testrunner/05-e2e-testing.md b/versioned_docs/version-v4.14/testing/stencil-testrunner/05-e2e-testing.md index 64280629a..c2a794710 100644 --- a/versioned_docs/version-v4.14/testing/stencil-testrunner/05-e2e-testing.md +++ b/versioned_docs/version-v4.14/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -225,6 +235,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.15/components/api.md b/versioned_docs/version-v4.15/components/api.md index 174f446d2..6051e207b 100644 --- a/versioned_docs/version-v4.15/components/api.md +++ b/versioned_docs/version-v4.15/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.15/components/component-lifecycle.md b/versioned_docs/version-v4.15/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.15/components/component-lifecycle.md +++ b/versioned_docs/version-v4.15/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.15/config/01-overview.md b/versioned_docs/version-v4.15/config/01-overview.md index 8d35ca59b..c800d076e 100644 --- a/versioned_docs/version-v4.15/config/01-overview.md +++ b/versioned_docs/version-v4.15/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.15/config/plugins.md b/versioned_docs/version-v4.15/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.15/config/plugins.md +++ b/versioned_docs/version-v4.15/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.15/framework-integration/angular.md b/versioned_docs/version-v4.15/framework-integration/angular.md index e608d0438..689ab7a12 100644 --- a/versioned_docs/version-v4.15/framework-integration/angular.md +++ b/versioned_docs/version-v4.15/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.15/output-targets/copy-tasks.md b/versioned_docs/version-v4.15/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.15/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.15/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.15/testing/stencil-testrunner/05-e2e-testing.md b/versioned_docs/version-v4.15/testing/stencil-testrunner/05-e2e-testing.md index 64280629a..c2a794710 100644 --- a/versioned_docs/version-v4.15/testing/stencil-testrunner/05-e2e-testing.md +++ b/versioned_docs/version-v4.15/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -225,6 +235,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.16/components/api.md b/versioned_docs/version-v4.16/components/api.md index 174f446d2..6051e207b 100644 --- a/versioned_docs/version-v4.16/components/api.md +++ b/versioned_docs/version-v4.16/components/api.md @@ -152,6 +152,15 @@ The following primitives can be imported from the `@stencil/core` package and us } ``` +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + - **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. __Type:__ `(ref: HTMLElement) => string`
diff --git a/versioned_docs/version-v4.16/components/component-lifecycle.md b/versioned_docs/version-v4.16/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.16/components/component-lifecycle.md +++ b/versioned_docs/version-v4.16/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.16/config/01-overview.md b/versioned_docs/version-v4.16/config/01-overview.md index 8d35ca59b..c800d076e 100644 --- a/versioned_docs/version-v4.16/config/01-overview.md +++ b/versioned_docs/version-v4.16/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.16/config/plugins.md b/versioned_docs/version-v4.16/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.16/config/plugins.md +++ b/versioned_docs/version-v4.16/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.16/framework-integration/angular.md b/versioned_docs/version-v4.16/framework-integration/angular.md index e608d0438..689ab7a12 100644 --- a/versioned_docs/version-v4.16/framework-integration/angular.md +++ b/versioned_docs/version-v4.16/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.16/output-targets/copy-tasks.md b/versioned_docs/version-v4.16/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.16/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.16/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.16/testing/stencil-testrunner/05-e2e-testing.md b/versioned_docs/version-v4.16/testing/stencil-testrunner/05-e2e-testing.md index 64280629a..c2a794710 100644 --- a/versioned_docs/version-v4.16/testing/stencil-testrunner/05-e2e-testing.md +++ b/versioned_docs/version-v4.16/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -225,6 +235,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.17/components/component-lifecycle.md b/versioned_docs/version-v4.17/components/component-lifecycle.md index 377dd6530..6b3cf3369 100644 --- a/versioned_docs/version-v4.17/components/component-lifecycle.md +++ b/versioned_docs/version-v4.17/components/component-lifecycle.md @@ -131,7 +131,7 @@ Even if some components may or may not be already loaded, the entire component h ## Async Lifecycle Methods -Lifecycle methods can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. diff --git a/versioned_docs/version-v4.17/config/01-overview.md b/versioned_docs/version-v4.17/config/01-overview.md index 8d35ca59b..c800d076e 100644 --- a/versioned_docs/version-v4.17/config/01-overview.md +++ b/versioned_docs/version-v4.17/config/01-overview.md @@ -108,6 +108,39 @@ enableCache: true Please see the [Extras docs](./extras.md). +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + ## globalScript The global script config option takes a file path as a string. diff --git a/versioned_docs/version-v4.17/config/plugins.md b/versioned_docs/version-v4.17/config/plugins.md index bb54c8a19..5ac6e4c8f 100644 --- a/versioned_docs/version-v4.17/config/plugins.md +++ b/versioned_docs/version-v4.17/config/plugins.md @@ -47,7 +47,7 @@ export const config = { - [@stencil/sass](https://www.npmjs.com/package/@stencil/sass) - [@stencil-community/postcss](https://www.npmjs.com/package/@stencil-community/postcss) -- (Deprecated) [@stencil/less](https://www.npmjs.com/package/@stencil/less) +- [@stencil-community/less](https://www.npmjs.com/package/@stencil-community/less) - (Deprecated) [@stencil/stylus](https://www.npmjs.com/package/@stencil/stylus) diff --git a/versioned_docs/version-v4.17/framework-integration/angular.md b/versioned_docs/version-v4.17/framework-integration/angular.md index e608d0438..689ab7a12 100644 --- a/versioned_docs/version-v4.17/framework-integration/angular.md +++ b/versioned_docs/version-v4.17/framework-integration/angular.md @@ -294,6 +294,22 @@ of your Angular workspace (`/packages/angular-workspace`), run the following com npx -p @angular/cli ng build component-library ``` +:::note +In the output of the `ng build` command you may see a warning that looks like this: + +``` +▲ [WARNING] The glob pattern import("./**/.entry.js") did not match any files [empty-glob] + +node_modules/@stencil/core/internal/client/index.js:3808:2: + 3808 │ `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVers... + ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``` + +This is a known issue in esbuild (used under the hood by `ng build`) and should +not cause an issue, but at present there's unfortunately no way to suppress +this warning. +::: + + + + + + + + + +``` \ No newline at end of file diff --git a/versioned_docs/version-v4.17/output-targets/copy-tasks.md b/versioned_docs/version-v4.17/output-targets/copy-tasks.md index 0b3340791..1e2d5eaa5 100644 --- a/versioned_docs/version-v4.17/output-targets/copy-tasks.md +++ b/versioned_docs/version-v4.17/output-targets/copy-tasks.md @@ -21,6 +21,61 @@ The `copy` attribute on these output targets expects an array of objects corresp https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 ``` +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + ## Examples ### Images in the `www` Output Target diff --git a/versioned_docs/version-v4.17/testing/stencil-testrunner/05-e2e-testing.md b/versioned_docs/version-v4.17/testing/stencil-testrunner/05-e2e-testing.md index 64280629a..c2a794710 100644 --- a/versioned_docs/version-v4.17/testing/stencil-testrunner/05-e2e-testing.md +++ b/versioned_docs/version-v4.17/testing/stencil-testrunner/05-e2e-testing.md @@ -24,6 +24,7 @@ Most methods are async and return Promises. Use `async` and `await` to declutter - `find(selector: string)`: Find an element that matches the selector. Similar to `document.querySelector`. - `setContent(html: string)`: Sets the content of a page. This is where you would include the markup of the component under test. +- `goto(url: string)`: open a page served by the dev server. URL has to start with `/`. - `setViewport(viewport: Viewport)`: Updates the page to emulate a device display. This is helpful for testing a component's behavior in different orientations and viewport sizes. - `waitForChanges()`: Both Stencil and Puppeteer have an asynchronous architecture, which is a good thing for performance. Since all calls are async, it's required that `await page.waitForChanges()` is called when changes are made to components. @@ -42,6 +43,15 @@ describe('example', () => { }); ``` +## Options + +The `newE2EPage` accepts the following options: + +- `html`: a HTML template, e.g. containing your Stencil component to be rendered in the browser (same as calling `page.setContent('...')`) +- `url`: opens a url to open a page served by the dev server (option will be ignored if `html` is set, same as calling `page.goto('...')`) +- `failOnConsoleError`: If set to `true`, Stencil will throw an error if a console error occurs (default: `false`) +- `failOnNetworkError`: If set to `true`, Stencil will throw an error if a network request fails (default: `false`) + ## Example End-to-end Test ```typescript @@ -225,6 +235,18 @@ const el = await page.find('.desktop'); expect(el).not.toBeDefined(); ``` +### Asynchronous Global Script + +If you are using an asynchronous [global script](/config/01-overview.md#globalscript), it may happen that your Stencil components haven't been hydrated at the time you are trying to interact with them. In this case it is recommend to wait for the hydration flag to be set on the component, e.g.: + +```ts +const page = await newE2EPage(); +await page.setContent(``); +await page.waitForSelector('.hydrated') +``` + +__Note:__ the hydrate selector may be different depending on whether you have a custom [`hydratedFlag`](/config/01-overview.md#hydratedflag) options set. + ## Caveat about e2e tests automation on CD/CI As it is a fairly common practice, you might want to automatically run your end-to-end tests on your Continuous Deployment/Integration (CD/CI) system. However, some environments might need you to tweak your configuration at times. If so, the `config` object in your `stencil.config.ts` file has a `testing` attribute that accepts parameters to modify how Headless Chrome is actually used in your pipeline. diff --git a/versioned_docs/version-v4.18/build-variables.md b/versioned_docs/version-v4.18/build-variables.md new file mode 100644 index 000000000..30cc41d9e --- /dev/null +++ b/versioned_docs/version-v4.18/build-variables.md @@ -0,0 +1,48 @@ +--- +title: Build Constants +description: Stencil has a number of add-ons that you can use with the build process. +slug: /build-variables +--- + +# Build Constants + +Build Constants in Stencil allow you to run specific code only when Stencil is running in development mode. This code is stripped from your bundles when doing a production build, therefore keeping your bundles as small as possible. + +### Using Build Constants + +Lets dive in and look at an example of how to use our build constants: + +```tsx +import { Component, Build } from '@stencil/core'; + +@Component({ + tag: 'stencil-app', + styleUrl: 'stencil-app.scss' +}) +export class StencilApp { + + componentDidLoad() { + if (Build.isDev) { + console.log('im in dev mode'); + } else { + console.log('im running in production'); + } + + if (Build.isBrowser) { + console.log('im in the browser'); + } else { + console.log('im in prerendering (server)'); + } + } +} +``` + +As you can see from this example, we just need to import `Build` from `@stencil/core` and then we can use the `isDev` constant to detect when we are running in dev mode or production mode. + +### Use Cases + +Some use cases we have come up with are: + +- Diagnostics code that runs in dev to make sure logic is working like you would expect +- `console.log()`'s that may be useful for debugging in dev mode but that you don't want to ship +- Disabling auth checks when in dev mode diff --git a/versioned_docs/version-v4.18/components/_category_.json b/versioned_docs/version-v4.18/components/_category_.json new file mode 100644 index 000000000..57bbce615 --- /dev/null +++ b/versioned_docs/version-v4.18/components/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Components", + "position": 2 +} diff --git a/versioned_docs/version-v4.18/components/api.md b/versioned_docs/version-v4.18/components/api.md new file mode 100644 index 000000000..6051e207b --- /dev/null +++ b/versioned_docs/version-v4.18/components/api.md @@ -0,0 +1,197 @@ +--- +title: Component API +sidebar_label: API +description: Component API +slug: /api +--- + +# Component API + +The whole API provided by stencil can be condensed in a set of decorators, lifecycles hooks and rendering methods. + + +## Decorators + +Decorators are a pure compiler-time construction used by stencil to collect all the metadata about a component, the properties, attributes and methods it might expose, the events it might emit or even the associated stylesheets. +Once all the metadata has been collected, all the decorators are removed from the output, so they don't incur any runtime overhead. + +- [@Component()](./component.md) declares a new web component +- [@Prop()](./properties.md#the-prop-decorator-prop) declares an exposed property/attribute +- [@State()](./state.md#the-state-decorator-state) declares an internal state of the component +- [@Watch()](./reactive-data.md#the-watch-decorator-watch) declares a hook that runs when a property or state changes +- [@Element()](./host-element.md#element-decorator) declares a reference to the host element +- [@Method()](./methods.md) declares an exposed public method +- [@Event()](./events.md#event-decorator) declares a DOM event the component might emit +- [@Listen()](./events.md#listen-decorator) listens for DOM events + + +## Lifecycle hooks + +- [connectedCallback()](./component-lifecycle.md#connectedcallback) +- [disconnectedCallback()](./component-lifecycle.md#disconnectedcallback) +- [componentWillLoad()](./component-lifecycle.md#componentwillload) +- [componentDidLoad()](./component-lifecycle.md#componentdidload) +- [componentShouldUpdate(newValue, oldValue, propName): boolean](./component-lifecycle.md#componentshouldupdate) +- [componentWillRender()](./component-lifecycle.md#componentwillrender) +- [componentDidRender()](./component-lifecycle.md#componentdidrender) +- [componentWillUpdate()](./component-lifecycle.md#componentwillupdate) +- [componentDidUpdate()](./component-lifecycle.md#componentdidupdate) +- **[render()](./templating-and-jsx.md)** + +## componentOnReady() + +This isn't a true "lifecycle" method that would be declared on the component class definition, but instead is a utility method that +can be used by an implementation consuming your Stencil component to detect when a component has finished its first render cycle. + +This method returns a promise which resolves after `componentDidRender()` on the _first_ render cycle. + +:::note +`componentOnReady()` only resolves once per component lifetime. If you need to hook into subsequent render cycle, use +`componentDidRender()` or `componentDidUpdate()`. +::: + +Executing code after `componentOnReady()` resolves could look something like this: + +```ts +// Get a reference to the element +const el = document.querySelector('my-component'); + +el.componentOnReady().then(() => { + // Place any code in here you want to execute when the component is ready + console.log('my-component is ready'); +}); +``` + +The availability of `componentOnReady()` depends on the component's compiled output type. This method is only available for lazy-loaded +distribution types ([`dist`](../output-targets/dist.md) and [`www`](../output-targets/www.md)) and, as such, is not available for +[`dist-custom-elements`](../output-targets/custom-elements.md) output. If you want to simulate the behavior of `componentOnReady()` for non-lazy builds, +you can implement a helper method to wrap the functionality similar to what the Ionic Framework does [here](https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/helpers.ts#L60-L79). + +## The `appload` event + +In addition to component-specific lifecycle hooks, a special event called `appload` will be emitted when the app and all of its child components have finished loading. You can listen for it on the `window` object. + +If you have multiple apps on the same page, you can determine which app emitted the event by checking `event.detail.namespace`. This will be the value of the [namespace config option](../config/01-overview.md#namespace) you've set in your Stencil config. + +```tsx +window.addEventListener('appload', (event) => { + console.log(event.detail.namespace); +}); +``` + +## Other + +The following primitives can be imported from the `@stencil/core` package and used within the lifecycle of a component: + +- [**Host**](./host-element.md): ``, is a functional component that can be used at the root of the render function to set attributes and event listeners to the host element itself. Refer to the [Host Element](./host-element.md) page for usage info. + +- **Fragment**: ``, often used via `<>...` syntax, lets you group elements without a wrapper node. + + To use this feature, ensure that the following TypeScript compiler options are set: + - [`jsxFragmentFactory` is set](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory) to "Fragment" + - [`jsxFactory` is set](https://www.typescriptlang.org/tsconfig#jsxFactory) to "h" + + __Type:__ `FunctionalComponent`
+ __Example:__ + ```tsx + import { Component, Fragment, h } from '@stencil/core' + @Component({ + tag: 'cmp-fragment', + }) + export class CmpFragment { + render() { + return ( + <> +
...
+
...
+
...
+ + ); + } + } + ``` + +- [**h()**](./templating-and-jsx.md): It's used within the `render()` to turn the JSX into Virtual DOM elements. + +- [**readTask()**](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing): Schedules a DOM-read task. The provided callback will be executed in the best moment to perform DOM reads without causing layout thrashing. + + __Type:__ `(task: Function) => void` + +- [**writeTask()**](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing): Schedules a DOM-write task. The provided callback will be executed in the best moment to perform DOM mutations without causing layout thrashing. + + __Type:__ `(task: Function) => void` + +- **forceUpdate()**: Schedules a new render of the given instance or element even if no state changed. Notice `forceUpdate()` is not synchronous and might perform the DOM render in the next frame. + + __Type:__ `(ref: HTMLElement) => void`
+ __Example:__ + ```ts + import { forceUpdate } from '@stencil/core' + + // inside a class component function + forceUpdate(this); + ``` + +- **getAssetPath()**: Gets the path to local assets. Refer to the [Assets](../guides/assets.md#getassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```tsx + import { Component, Prop, getAssetPath, h } from '@stencil/core' + @Component({ + tag: 'cmp-asset', + }) + export class CmpAsset { + @Prop() icon: string; + + render() { + return ( + + ); + } + } + ``` + +- **setAssetPath()**: Sets the path for Stencil to resolve local assets. Refer to the [Assets](../guides/assets.md#setassetpath) page for usage info. + + __Type:__ `(path: string) => string`
+ __Example:__ + ```ts + import { setAssetPath } from '@stencil/core'; + setAssetPath(`{window.location.origin}/`); + ``` + +- **setMode()**: Sets the style mode of a component. Refer to the [Styling](./styling.md#style-modes) page for usage info. + + __Type:__ `(ref: HTMLElement) => string`
+ __Example:__ + ```ts + import { setMode } from '@stencil/core' + + // set mode based on a property + setMode((el) => el.getAttribute('mode')); + ``` + +- **getMode()**: Get the current style mode of your application. Refer to the [Styling](./styling.md#style-modes) page for usage info. + + __Type:__ `(ref: HTMLElement) => string`
+ __Example:__ + ```ts + import { getMode } from '@stencil/core' + + getMode(this); + ``` + +- **getElement()**: Retrieve a Stencil element for a given reference. + + __Type:__ `(ref: getElement) => string`
+ __Example:__ + ```ts + import { getElement } from '@stencil/core' + + const stencilComponent = getElement(document.querySelector('my-cmp')) + if (stencilComponent) { + stencilComponent.componentOnReady().then(() => { ... }) + } + ``` + diff --git a/versioned_docs/version-v4.18/components/component-lifecycle.md b/versioned_docs/version-v4.18/components/component-lifecycle.md new file mode 100644 index 000000000..6b3cf3369 --- /dev/null +++ b/versioned_docs/version-v4.18/components/component-lifecycle.md @@ -0,0 +1,183 @@ +--- +title: Component Lifecycle Methods +sidebar_label: Lifecycle Methods +description: Component Lifecycle Methods +slug: /component-lifecycle +--- + +# Component Lifecycle Methods + +Components have numerous lifecycle methods which can be used to know when the component "will" and "did" load, update, and render. These methods can be added to a component to hook into operations at the right time. + +Implement one of the following methods within a component class and Stencil will automatically call them in the right order: + +import LifecycleMethodsChart from '@site/src/components/LifecycleMethodsChart'; + + + +## connectedCallback() + +Called every time the component is connected to the DOM. +When the component is first connected, this method is called before `componentWillLoad`. + +It's important to note that this method can be called more than once, every time, the element is **attached** or **moved** in the DOM. For logic that needs to run every time the element is attached or moved in the DOM, it is considered a best practice to use this lifecycle method. + +```tsx +const el = document.createElement('my-cmp'); +document.body.appendChild(el); +// connectedCallback() called +// componentWillLoad() called (first time) + +el.remove(); +// disconnectedCallback() + +document.body.appendChild(el); +// connectedCallback() called again, but `componentWillLoad()` is not. +``` + + +This `lifecycle` hook follows the same semantics as the one described by the [Custom Elements Spec](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) + +## disconnectedCallback() + +Called every time the component is disconnected from the DOM, ie, it can be dispatched more than once, DO not confuse with a "onDestroy" kind of event. + +This `lifecycle` hook follows the same semantics as the one described by the [Custom Elements Spec](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements). + +## componentWillLoad() + +Called once just after the component is first connected to the DOM. Since this method is only called once, it's a good place to load data asynchronously and to setup the state without triggering extra re-renders. + +A promise can be returned, that can be used to wait for the first `render()`. + +## componentDidLoad() + +Called once just after the component is fully loaded and the first `render()` occurs. + +## componentShouldUpdate() + +This hook is called when a component's [`Prop`](./properties.md) or [`State`](./state.md) property changes and a rerender is about to be requested. This hook receives three arguments: the new value, the old value and the name of the changed state. It should return a boolean to indicate if the component should rerender (`true`) or not (`false`). + +A couple of things to notice is that this method will not be executed before the initial render, that is, when the component is first attached to the dom, nor when a rerender is already scheduled in the next frame. + +Let’s say the following two props of a component change synchronously: + +```tsx +component.somePropA = 42; +component.somePropB = 88; +``` + +The `componentShouldUpdate` will be first called with arguments: `42`, `undefined` and `somePropA`. If it does return `true`, the hook will not be called again since the rerender is already scheduled to happen. Instead, if the first hook returned `false`, then `componentShouldUpdate` will be called again with `88`, `undefined` and `somePropB` as arguments, triggered by the `component.somePropB = 88` mutation. + +Since the execution of this hook might be conditioned, it's not good to rely on it to watch for prop changes, instead use the `@Watch` decorator for that. + +## componentWillRender() + +Called before every `render()`. + +A promise can be returned, that can be used to wait for the upcoming render. + +## componentDidRender() + +Called after every `render()`. + + +## componentWillUpdate() + +Called when the component is about to be updated because some `Prop()` or `State()` changed. +It's never called during the first `render()`. + +A promise can be returned, that can be used to wait for the next render. + + +## componentDidUpdate() + +Called just after the component updates. +It's never called during the first `render()`. + + +## Rendering State + +It's always recommended to make any rendered state updates within `componentWillRender()`, since this is the method which get called _before_ the `render()` method. Alternatively, updating rendered state with the `componentDidLoad()`, `componentDidUpdate()` and `componentDidRender()` methods will cause another rerender, which isn't ideal for performance. + +If state _must_ be updated in `componentDidUpdate()` or `componentDidRender()`, it has the potential of getting components stuck in an infinite loop. If updating state within `componentDidUpdate()` is unavoidable, then the method should also come with a way to detect if the props or state is "dirty" or not (is the data actually different or is it the same as before). By doing a dirty check, `componentDidUpdate()` is able to avoid rendering the same data, and which in turn calls `componentDidUpdate()` again. + + +## Lifecycle Hierarchy + +A useful feature of lifecycle methods is that they take their child component's lifecycle into consideration too. For example, if the parent component, `cmp-a`, has a child component, `cmp-b`, then `cmp-a` isn't considered "loaded" until `cmp-b` has finished loading. Another way to put it is that the deepest components finish loading first, then the `componentDidLoad()` calls bubble up. + +It's also important to note that even though Stencil can lazy-load components, and has asynchronous rendering, the lifecycle methods are still called in the correct order. So while the top-level component could have already been loaded, all of its lifecycle methods are still called in the correct order, which means it'll wait for a child components to finish loading. The same goes for the exact opposite, where the child components may already be ready while the parent isn't. + +In the example below we have a simple hierarchy of components. The numbered list shows the order of which the lifecycle methods will fire. + +```markup + + + + + +``` + +1. `cmp-a` - `componentWillLoad()` +2. `cmp-b` - `componentWillLoad()` +3. `cmp-c` - `componentWillLoad()` +4. `cmp-c` - `componentDidLoad()` +5. `cmp-b` - `componentDidLoad()` +6. `cmp-a` - `componentDidLoad()` + +Even if some components may or may not be already loaded, the entire component hierarchy waits on its child components to finish loading and rendering. + + +## Async Lifecycle Methods + +Some lifecycle methods, e.g. `componentWillRender`, `componentWillLoad` and `componentWillUpdate`, can also return promises which allows the method to asynchronously retrieve data or perform any async tasks. A great example of this is fetching data to be rendered in a component. For example, this very site you're reading first fetches content data before rendering. But because `fetch()` is async, it's important that `componentWillLoad()` returns a `Promise` to ensure its parent component isn't considered "loaded" until all of its content has rendered. + +Below is a quick example showing how `componentWillLoad()` is able to have its parent component wait on it to finish loading its data. + +```tsx +componentWillLoad() { + return fetch('/some-data.json') + .then(response => response.json()) + .then(data => { + this.content = data; + }); +} +``` + + +## Example + +This simple example shows a clock and updates the current time every second. The timer is started when the component is added to the DOM. Once it's removed from the DOM, the timer is stopped. + +```tsx +import { Component, State, h } from '@stencil/core'; + +@Component({ + tag: 'custom-clock' +}) +export class CustomClock { + + timer: number; + + @State() time: number = Date.now(); + + connectedCallback() { + this.timer = window.setInterval(() => { + this.time = Date.now(); + }, 1000); + } + + disconnectedCallback() { + window.clearInterval(this.timer); + } + + render() { + const time = new Date(this.time).toLocaleTimeString(); + + return ( + { time } + ); + } +} +``` diff --git a/versioned_docs/version-v4.18/components/component.md b/versioned_docs/version-v4.18/components/component.md new file mode 100644 index 000000000..a45fd06fe --- /dev/null +++ b/versioned_docs/version-v4.18/components/component.md @@ -0,0 +1,392 @@ +--- +title: Component Decorator +sidebar_label: Component +description: Documentation for the @Component decorator +slug: /component +--- + +# Component Decorator + +`@Component()` is a decorator that designates a TypeScript class as a Stencil component. +Every Stencil component gets transformed into a web component at build time. + +```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + // additional options +}) +export class TodoList { + // implementation omitted +} +``` + +## Component Options + +The `@Component()` decorator takes one argument, an object literal containing configuration options for the component. +This allows each component to be individually configured to suit the unique needs of each project. + +Each option, its type, and whether it's required is described below. + +### tag + +**Required** + +**Type: `string`** + +**Details:**
+This value sets the name of the custom element that Stencil will generate. +To adhere to the [HTML spec](https://html.spec.whatwg.org/#valid-custom-element-name), the tag name must contain a dash ('-'). + +Ideally, the tag name is a globally unique value. +Having a globally unique value helps prevent naming collisions with the global `CustomElementsRegistry`, where all custom elements are defined. +It's recommended to choose a unique prefix for all your components within the same collection. + +**Example**:
+```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', +}) +export class TodoList { + // implementation omitted +} +``` +After compilation, the component defined in `TodoList` can be used in HTML or another TSX file: +```html + + +``` +```tsx +{/* Here we use the component in a TSX file */} + +``` + +### assetsDirs + +**Optional** + +**Type: `string[]`** + +**Details:**
+`assetsDirs` is an array of relative paths from the component to a directory containing the static files (assets) the component requires. + +**Example**:
+Below is an example project's directory structure containing an example component and assets directory. + +``` +src/ +└── components/ + ├── assets/ + │ └── sunset.jpg + └── todo-list.tsx +``` + +Below, the `todo-list` component will correctly load the `sunset.jpg` image from the `assets/` directory, using Stencil's [`getAssetPath()`](../guides/assets.md#getassetpath). + +```tsx +import { Component, Prop, getAssetPath, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + // 1. assetsDirs lists the 'assets' directory as a relative (sibling) + // directory + assetsDirs: ['assets'] +}) +export class TodoList { + image = "sunset.jpg"; + + render() { + // 2. the asset path is retrieved relative to the asset base path to use in + // the tag + const imageSrc = getAssetPath(`./assets/${this.image}`); + return + } +} +``` + +In the example above, the following allows `todo-list` to display the provided asset: +1. The `TodoList`'s `@Component()` decorator has the `assetsDirs` property, and lists the file's sibling directory, `assets/`. + This will copy the `assets` directory over to the distribution directory. +2. Stencil's [`getAssetPath()`](../guides/assets.md#getassetpath) is used to retrieve the path to the image to be used in the `` tag + +For more information on configuring assets, please see Stencil's [Assets Guide](../guides/assets.md) + + +### formAssociated + +**Optional** + +**Type: `boolean`** + +**Default: `false`** + +If `true` the component will be +[form-associated](https://html.spec.whatwg.org/dev/custom-elements.html#form-associated-custom-element), +allowing you to take advantage of the +[`ElementInternals`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals) +API to enable your Stencil component to participate in forms. + +A minimal form-associated Stencil component could look like this: + +```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'form-associated', + formAssociated: true +}) +export class FormAssociated { + render() { + return form associated! + } +} +``` + +See the documentation for [form-associated components](./form-associated.md) +for more info and examples. + +### scoped + +**Optional** + +**Type: `boolean`** + +**Default: `false`** + +**Details:**
+If `true`, the component will use [scoped stylesheets](./styling.md#scoped-css). + +Scoped CSS is an alternative to using the native [shadow DOM](./styling.md#shadow-dom) style encapsulation. +It appends a data attribute to your styles to make them unique and thereby scope them to your component. +It does not, however, prevent styles from the light DOM from seeping into your component. + +To use the native [shadow DOM](./styling.md#shadow-dom), see the configuration for [`shadow`](#shadow). + +This option cannot be set to `true` if `shadow` is enabled. + +**Example**:
+```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + scoped: true +}) +export class TodoList { + // implementation omitted +} +``` + +### shadow + +**Optional** + +**Type: `boolean | { delegatesFocus: boolean }`** + +**Default: `false`** + +**Details:**
+If `true`, the component will use [native Shadow DOM encapsulation](./styling.md#shadow-dom). +It will fall back to `scoped` if the browser does not support shadow-dom natively. + +`delegatesFocus` is a property that [provides focus](https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/delegatesFocus) to the first focusable entry in a component using Shadow DOM. +If an object literal containing `delegatesFocus` is provided, the component will use [native Shadow DOM encapsulation](./styling.md#shadow-dom), regardless of the value assigned to `delegatesFocus`. + +When `delegatesFocus` is set to `true`, the component will have `delegatesFocus: true` added to its shadow DOM. + +When `delegatesFocus` is `true` and a non-focusable part of the component is clicked: +- the first focusable part of the component is given focus +- the component receives any available `focus` styling + +If `shadow` is set to `false`, the component will not use native shadow DOM encapsulation. + +This option cannot be set to enabled if `scoped` is enabled. + +**Example 1**:
+```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + shadow: true +}) +export class TodoList { + // implementation omitted +} +``` + +**Example 2**:
+```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + shadow: { + delegatesFocus: true, + } +}) +export class TodoList { + // implementation omitted +} +``` + +### styleUrl + +**Optional** + +**Type: `string`** + +**Details:**
+Relative URL to an external stylesheet containing styles to apply to your component. +Out of the box, Stencil will only process CSS files (files ending with `.css`). +Support for additional CSS variants, like Sass, can be added via [a plugin](https://stenciljs.com/docs/plugins#related-plugins). + +**Example**:
+Below is an example project's directory structure containing an example component and stylesheet. +``` +src/ +└── components/ + ├── todo-list.css + └── todo-list.tsx +``` + +By setting `styleUrl`, Stencil will apply the `todo-list.css` stylesheet to the `todo-list` component: + +```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + styleUrl: './todo-list.css', +}) +export class TodoList { + // implementation omitted +} +``` + +### styleUrls + +**Optional** + +**Type: `string[] | { [modeName: string]: string | string[]; }`** + +**Details:**
+A list of relative URLs to external stylesheets containing styles to apply to your component. + +Alternatively, an object can be provided that maps a named "mode" to one or more stylesheets. + +Out of the box, Stencil will only process CSS files (ending with `.css`). +Support for additional CSS variants, like Sass, can be added via [a plugin](https://stenciljs.com/docs/plugins#related-plugins). + +**Example**:
+Below is an example project's directory structure containing an example component and stylesheet. +``` +src/ +└── components/ + ├── todo-list-1.css + ├── todo-list-2.css + └── todo-list.tsx +``` + +By setting `styleUrls`, Stencil will apply both stylesheets to the `todo-list` component: + +```tsx title="Using an array of styles" +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + styleUrls: ['./todo-list-1.css', './todo-list-2.css'] +}) +export class TodoList { + // implementation omitted +} +``` + +```tsx title="Using modes" +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + styleUrls: { + ios: 'todo-list-1.ios.scss', + md: 'todo-list-2.md.scss', + } +}) +export class TodoList { + // implementation omitted +} +``` + +Read more on styling modes in the Components [Styling](./styling.md#style-modes) section. + +### styles + +**Optional** + +**Type: `string | { [modeName: string]: any }`** + +**Details:**
+A string that contains inlined CSS instead of using an external stylesheet. +The performance characteristics of this feature are the same as using an external stylesheet. + +When using `styles`, only CSS is permitted. +See [`styleUrl`](#styleurl) if you need more advanced features. + +**Example**:
+```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'todo-list', + styles: 'div { background-color: #fff }' +}) +export class TodoList { + // implementation omitted +} +``` + +## Embedding or Nesting Components + +Components can be composed easily by adding the HTML tag to the JSX code. Since the components are just HTML tags, nothing needs to be imported to use a Stencil component within another Stencil component. + +Here's an example of using a component within another component: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'my-embedded-component' +}) +export class MyEmbeddedComponent { + @Prop() color: string = 'blue'; + + render() { + return ( +
My favorite color is {this.color}
+ ); + } +} +``` + +```tsx +import { Component, h } from '@stencil/core'; + +@Component({ + tag: 'my-parent-component' +}) +export class MyParentComponent { + + render() { + return ( +
+ +
+ ); + } +} +``` + +The `my-parent-component` includes a reference to the `my-embedded-component` in the `render()` function. diff --git a/versioned_docs/version-v4.18/components/events.md b/versioned_docs/version-v4.18/components/events.md new file mode 100644 index 000000000..96ed92f07 --- /dev/null +++ b/versioned_docs/version-v4.18/components/events.md @@ -0,0 +1,225 @@ +--- +title: Events +sidebar_label: Events +description: Events +slug: /events +--- + +# Events + +There is **NOT** such a thing as *stencil events*, instead, Stencil encourages the use of [DOM events](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events). +However, Stencil does provide an API to specify the events a component can emit, and the events a component listens to. It does so with the `Event()` and `Listen()` decorators. + +## Event Decorator + +Components can emit data and events using the Event Emitter decorator. + +To dispatch [Custom DOM events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events) for other components to handle, use the `@Event()` decorator. + +```tsx +import { Event, EventEmitter } from '@stencil/core'; + +... +export class TodoList { + + @Event() todoCompleted: EventEmitter; + + todoCompletedHandler(todo: Todo) { + this.todoCompleted.emit(todo); + } +} +``` + +The code above will dispatch a custom DOM event called `todoCompleted`. + +The `Event(opts: EventOptions)` decorator optionally accepts an options object to shape the behavior of dispatched events. The options and defaults are described below. + +```tsx +export interface EventOptions { + /** + * A string custom event name to override the default. + */ + eventName?: string; + /** + * A Boolean indicating whether the event bubbles up through the DOM or not. + */ + bubbles?: boolean; + + /** + * A Boolean indicating whether the event is cancelable. + */ + cancelable?: boolean; + + /** + * A Boolean value indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM. + */ + composed?: boolean; +} +``` + +Example: + +```tsx +import { Event, EventEmitter } from '@stencil/core'; + +... +export class TodoList { + + // Event called 'todoCompleted' that is "composed", "cancellable" and it will bubble up! + @Event({ + eventName: 'todoCompleted', + composed: true, + cancelable: true, + bubbles: true, + }) todoCompleted: EventEmitter; + + todoCompletedHandler(todo: Todo) { + const event = this.todoCompleted.emit(todo); + if(!event.defaultPrevented) { + // if not prevented, do some default handling code + } + } +} +``` + +:::note +In the case where the Stencil `Event` type conflicts with the native web `Event` type, there are two possible solutions: + +1. Import aliasing: +```tsx +import { Event as StencilEvent, EventEmitter } from '@stencil/core'; + +@StencilEvent() myEvent: EventEmitter<{value: string, ev: Event}>; +``` + +2. Namespace the native web `Event` type with `globalThis`: +```tsx +@Event() myEvent: EventEmitter<{value: string, ev: globalThis.Event}>; +``` +::: + +## Listen Decorator + +The `Listen()` decorator is for listening to DOM events, including the ones dispatched from `@Events`. The event listeners are automatically added and removed when the component gets added or removed from the DOM. + +In the example below, assume that a child component, `TodoList`, emits a `todoCompleted` event using the `EventEmitter`. + +```tsx +import { Listen } from '@stencil/core'; + +... +export class TodoApp { + + @Listen('todoCompleted') + todoCompletedHandler(event: CustomEvent) { + console.log('Received the custom todoCompleted event: ', event.detail); + } +} +``` + +### Listen's options + +The `@Listen(eventName, opts?: ListenOptions)` includes a second optional argument that can be used to configure how the DOM event listener is attached. + +```tsx +export interface ListenOptions { + target?: 'body' | 'document' | 'window'; + capture?: boolean; + passive?: boolean; +} +``` + +The available options are `target`, `capture` and `passive`: + + +#### target + +Handlers can also be registered for an event other than the host itself. +The `target` option can be used to change where the event listener is attached, this is useful for listening to application-wide events. + +In the example below, we're going to listen for the scroll event, emitted from `window`: + +```tsx + @Listen('scroll', { target: 'window' }) + handleScroll(ev) { + console.log('the body was scrolled', ev); + } +``` + +#### passive + +By default, Stencil uses several heuristics to determine if it must attach a `passive` event listener or not. The `passive` option can be used to change the default behavior. + +Please check out [https://developers.google.com/web/updates/2016/06/passive-event-listeners](https://developers.google.com/web/updates/2016/06/passive-event-listeners) for further information. + + +#### capture + +Event listener attached with `@Listen` does not "capture" by default. +When a event listener is set to "capture", it means the event will be dispatched during the "capture phase". +Check out [https://www.quirksmode.org/js/events_order.html](https://www.quirksmode.org/js/events_order.html) for further information. + + +```tsx + @Listen('click', { capture: true }) + handleClick(ev) { + console.log('click'); + } +``` + +## Keyboard events + +For keyboard events, you can use the standard `keydown` event in `@Listen()` and use `event.keyCode` or `event.which` to get the key code, or `event.key` for the string representation of the key. + +```tsx +@Listen('keydown') +handleKeyDown(ev: KeyboardEvent){ + if (ev.key === 'ArrowDown'){ + console.log('down arrow pressed') + } +} +``` +More info on event key strings can be found in the [w3c spec](https://www.w3.org/TR/uievents-key/#named-key-attribute-values). + + +## Using events in JSX + +Within a stencil compiled application or component you can also bind listeners to events directly in JSX. This works very similar to normal DOM events such as `onClick`. + +Let's use our TodoList component from above: + +```tsx +import { Event, EventEmitter } from '@stencil/core'; + +... +export class TodoList { + + @Event() todoCompleted: EventEmitter; + + todoCompletedHandler(todo: Todo) { + this.todoCompleted.emit(todo); + } +} +``` + +We can now listen to this event directly on the component in our JSX using the following syntax: + +```tsx + this.someMethod(ev)} /> +``` + +This property is generated automatically and is prefixed with "on". For example, if the event emitted is called `todoDeleted` the property will be called `onTodoDeleted`: + +```tsx + this.someOtherMethod(ev)} /> +``` + +## Listening to events from a non-JSX element + +```tsx + + +``` diff --git a/versioned_docs/version-v4.18/components/form-associated.md b/versioned_docs/version-v4.18/components/form-associated.md new file mode 100644 index 000000000..f434a78ed --- /dev/null +++ b/versioned_docs/version-v4.18/components/form-associated.md @@ -0,0 +1,298 @@ +--- +title: Form-Associated Components +sidebar_label: Form-Associated Components +description: Form-Associated Stencil Components +slug: /form-associated +--- + +# Building Form-Associated Components in Stencil + +As of v4.5.0, Stencil has support for form-associated custom elements. This +allows Stencil components to participate in a rich way in HTML forms, +integrating with native browser features for validation and accessibility while +maintaining encapsulation and control over their styling and presentation. + +:::caution +Browser support for the APIs that this feature depends on is still not +universal[^1] and the Stencil team has no plans at present to support or +incorporate any polyfills for the browser functionality. Before you ship +form-associated Stencil components make sure that the browsers you need to +support have shipped the necessary APIs. +::: + +## Creating a Form-Associated Component + +A form-associated Stencil component is one which sets the new [`formAssociated`](./component.md#formassociated) +option in the argument to the `@Component` +decorator to `true`, like so: + +```tsx +import { Component } from '@stencil/core'; + +@Component({ + tag: 'my-face', + formAssociated: true, +}) +export class MyFACE { +} +``` + +This element will now be marked as a form-associated custom element via the +[`formAssociated`](https://html.spec.whatwg.org/#custom-elements-face-example) +static property, but by itself this is not terribly useful. + +In order to meaningfully interact with a `
` element that is an ancestor +of our custom element we'll need to get access to an +[`ElementInternals`](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals) +object corresponding to our element instance. Stencil provides a decorator, +`@AttachInternals`, which does just this, allowing you to decorate a property on +your component and bind an `ElementInternals` object to that property which you +can then use to interact with the surrounding form. + +:::info +Under the hood the `AttachInternals` decorator makes use of the very similarly +named +[`attachInternals`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals) +method on `HTMLElement` to associate your Stencil component with an ancestor +`` element. During compilation, Stencil will generate code that calls +this method at an appropriate point in the component lifecycle for both +[lazy](../output-targets/dist.md) and [custom elements](../output-targets/custom-elements.md) builds. +::: + +A Stencil component using this API to implement a custom text input could look +like this: + +```tsx title="src/components/custom-text-input.tsx" +import { Component, h, AttachInternals, State } from '@stencil/core'; + +@Component({ + tag: 'custom-text-input', + shadow: true, + formAssociated: true +}) +export class CustomTextInput { + @State() value: string; + + @AttachInternals() internals: ElementInternals; + + handleChange(event) { + this.value = event.target.value; + this.internals.setFormValue(event.target.value); + } + + componentWillLoad() { + this.internals.setFormValue("a default value"); + } + + render() { + return ( + this.handleChange(event)} + /> + ) + } +} +``` + +If this component is rendered within a `` element like so: + + +```html + + +
+``` + +then it will automatically be linked up to the surrounding form. The +`ElementInternals` object found at `this.internals` will have a bunch of +methods on it for interacting with that form and getting key information out of +it. + +In our `` example above we use the +[`setFormValue`](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue) +method to set a value in the surrounding form. This will read the `name` +attribute off of the element and use it when setting the value, so the value +typed by a user into the `input` will added to the form under the +`"my-custom-input"` name. + +This example just scratches the surface, and a great deal more is possible with +the `ElementInternals` API, including [setting the element's +validity](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setValidity), +reading the validity state of the form, reading other form values, and more. + +## Lifecycle Callbacks + +Stencil allows developers building form-associated custom elements to define a +[standard series of lifecycle +callbacks](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions) +which enable their components to react dynamically to events in their +lifecycle. These could allow fetching data when a form loads, changing styles +when a form's `disabled` state is toggled, resetting form data cleanly, and more. + +### `formAssociatedCallback` + +This callback is called when the browser both associates the element with and +disassociates the element from a form element. The function is called with the +form element as an argument. This could be used to set an `ariaLabel` when the +form is ready to use, like so: + +```tsx title='src/components/form-associated-cb.tsx' +import { Component, h, AttachInternals } from '@stencil/core'; + +@Component({ + tag: 'form-associated', + formAssociated: true, +}) +export class FormAssociatedCmp { + @AttachInternals() + internals: ElementInternals; + + formAssociatedCallback(form) { + form.ariaLabel = 'formAssociated called'; + } + + render() { + return ; + } +} +``` + +### `formDisabledCallback` + +This is called whenever the `disabled` state on the element _changes_. This +could be used to keep a CSS class in sync with the disabled state, like so: + +```tsx title='src/components/form-disabled-cb.tsx' +import { Component, h, State } from '@stencil/core'; + +@Component({ + tag: 'form-disabled-cb', + formAssociated: true, +}) +export class MyComponent { + @State() cssClass: string = ""; + + formDisabledCallback(disabled: boolean) { + if (disabled) { + this.cssClass = "background-mode"; + } else { + this.cssClass = ""; + } + } + + render() { + return + } +} +``` + +### `formResetCallback` + +This is called when the form is reset, and should be used to reset the +form-associated component's internal state and validation. For example, you +could do something like the following: + +```tsx title="src/components/form-reset-cb.tsx" +import { Component, h, AttachInternals } from '@stencil/core'; + +@Component({ + tag: 'form-reset-cb', + formAssociated: true, +}) +export class MyComponent { + @AttachInternals() + internals: ElementInternals; + + formResetCallback() { + this.internals.setValidity({}); + this.internals.setFormValue(""); + } + + render() { + return + } +} +``` + +### `formStateRestoreCallback` + +This method will be called in the event that the browser automatically fills +out your form element, an event that could take place in two different +scenarios. The first is that the browser can restore the state of an element +after navigating or restarting, and the second is that an input was made using a +form auto-filling feature. + +In either case, in order to correctly reset itself your form-associated component +will need the previously selected value, but other state may also be necessary. +For instance, the form value to be submitted for a date picker component would +be a specific date, but in order to correctly restore the component's visual +state it might also be necessary to know whether the picker should display a +week or month view. + +The +[`setFormValue`](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue) +method on `ElementInternals` provides some support for this use-case, allowing +you to submit both a _value_ and a _state_, where the _state_ is not added to +the form data sent to the server but could be used for storing some +client-specific state. For instance, a pseudocode sketch of a date picker +component that correctly restores whether the 'week' or 'month' view is active +could look like: + +```tsx title="src/components/fa-date-picker.tsx" +import { Component, h, State, AttachInternals } from '@stencil/core'; + +@Component({ + tag: 'fa-date-picker', + formAssociated: true, +}) +export class MyDatePicker { + @State() value: string = ""; + @State() view: "weeks" | "months" = "weeks"; + + @AttachInternals() + internals: ElementInternals; + + onInputChange(e) { + e.preventDefault(); + const date = e.target.value; + this.setValue(date); + } + + setValue(date: string) { + // second 'state' parameter is used to store both + // the input value (`date`) _and_ the current view + this.internals.setFormValue(date, `${date}#${this.view}`); + } + + formStateRestoreCallback(state, _mode) { + const [date, view] = state.split("#"); + this.view = view; + this.setValue(date); + } + + render() { + return
+ Mock Date Picker, mode: {this.view} + this.onInputChange(e)}> +
+ } +} +``` + +Note that the `formStateRestoreCallback` also receives a second argument, +`mode`, which can be either `"restore"` or `"autocomplete"`, indicating the +reason for the form restoration. + +For more on form restoration, including a complete example, check out [this +great blog post on the +subject](https://web.dev/articles/more-capable-form-controls#restoring-form-state). + +## Resources + +- [WHATWG specification for form-associated custom elements](https://html.spec.whatwg.org/dev/custom-elements.html#form-associated-custom-elements) +- [ElementInternals and Form-Associated Custom Elements](https://webkit.org/blog/13711/elementinternals-and-form-associated-custom-elements/) from the WebKit blog +- [Web.dev post detailing how form-associated lifecycle callbacks work](https://web.dev/articles/more-capable-form-controls#lifecycle_callbacks) + +[^1]: See https://caniuse.com/?search=attachInternals for up-to-date adoption estimates. diff --git a/versioned_docs/version-v4.18/components/functional-components.md b/versioned_docs/version-v4.18/components/functional-components.md new file mode 100644 index 000000000..cd3b27af2 --- /dev/null +++ b/versioned_docs/version-v4.18/components/functional-components.md @@ -0,0 +1,108 @@ +--- +title: Functional Components +sidebar_label: Functional Components +description: Functional Components +slug: /functional-components +--- + +# Working with Functional Components + +Functional components are quite different to normal Stencil web components because they are a part of Stencil's JSX compiler. A functional component is basically a function that takes an object of props and turns it into JSX. + +```tsx +const Hello = props =>

Hello, {props.name}!

; +``` + +When the JSX transpiler encounters such a component, it will take its attributes, pass them into the function as the `props` object, and replace the component with the JSX that is returned by the function. + +```tsx + +``` + +Functional components also accept a second argument `children`. + +```tsx +const Hello = (props, children) => [ +

Hello, {props.name}

, + children +]; +``` + +The JSX transpiler passes all child elements of the component as an array into the function's `children` argument. + +```tsx + +

I'm a child element.

+
+``` + +Stencil provides a `FunctionalComponent` generic type that allows to specify an interface for the component's properties. + +```tsx +// Hello.tsx + +import { FunctionalComponent, h } from '@stencil/core'; + +interface HelloProps { + name: string; +} + +export const Hello: FunctionalComponent = ({ name }) => ( +

Hello, {name}!

+); +``` + +## Working with children + +The second argument of a functional component receives the passed children, but in order to work with them, `FunctionalComponent` provides a utils object that exposes a `map()` method to transform the children, and a `forEach()` method to read them. Reading the `children` array is not recommended since the stencil compiler can rename the vNode properties in prod mode. + +```tsx +export interface FunctionalUtilities { + forEach: (children: VNode[], cb: (vnode: ChildNode, index: number, array: ChildNode[]) => void) => void; + map: (children: VNode[], cb: (vnode: ChildNode, index: number, array: ChildNode[]) => ChildNode) => VNode[]; +} +export interface ChildNode { + vtag?: string | number | Function; + vkey?: string | number; + vtext?: string; + vchildren?: VNode[]; + vattrs?: any; + vname?: string; +} +``` + +**Example:** + +```tsx +export const AddClass: FunctionalComponent = (_, children, utils) => ( + utils.map(children, child => ({ + ...child, + vattrs: { + ...child.vattrs, + class: `${child.vattrs.class} add-class` + } + } + )) +); +``` + +:::note +When using a functional component in JSX, its name must start with a capital letter. Therefore it makes sense to export it as such. +::: + + +## Disclaimer + +There are a few major differences between functional components and class components. Since functional components are just syntactic sugar within JSX, they... + +* aren't compiled into web components, +* don't create a DOM node, +* don't have a Shadow DOM or scoped styles, +* don't have lifecycle hooks, +* are stateless. + +When deciding whether to use functional components, one concept to keep in mind is that often the UI of your application can be a function of its state, i. e., given the same state, it always renders the same UI. If a component has to hold state, deal with events, etc, it should probably be a class component. If a component's purpose is to simply encapsulate some markup so it can be reused across your app, it can probably be a functional component (especially if you're using a component library and thus don't need to style it). + +:::caution +Stencil does not support re-exporting a functional component from a "barrel file" and dynamically rendering it in another component. This is a [known limitation](https://github.com/ionic-team/stencil/issues/5246) within Stencil. Instead, either use class components and remove the import or import the functional component directly. +::: \ No newline at end of file diff --git a/versioned_docs/version-v4.18/components/host-element.md b/versioned_docs/version-v4.18/components/host-element.md new file mode 100644 index 000000000..c391fbe35 --- /dev/null +++ b/versioned_docs/version-v4.18/components/host-element.md @@ -0,0 +1,159 @@ +--- +title: Working with host elements +sidebar_label: Host Element +description: Working with host elements +slug: /host-element +--- + +# Working with host elements + +Stencil components render their children declaratively in their `render` method [using JSX](./templating-and-jsx.md). Most of the time, the `render()` function describes the children elements that are about to be rendered, but it can also be used to render attributes of the host element itself. + + +## `` + +The `Host` functional component can be used at the root of the render function to set attributes and event listeners to the host element itself. This works just like any other JSX: + +```tsx +// Host is imported from '@stencil/core' +import { Component, Host, h } from '@stencil/core'; + +@Component({tag: 'todo-list'}) +export class TodoList { + @Prop() open = false; + render() { + return ( + + ) + } +} +``` + +If `this.open === true`, it will render: +```tsx + +``` + +similarly, if `this.open === false`: + +```tsx + +``` + +`` is a virtual component, a virtual API exposed by stencil to declaratively set the attributes of the host element, it will never be rendered in the DOM, i.e. you will never see `` in Chrome Dev Tools for instance. + + +### `` can work as a `` + +`` can also be used when more than one component needs to be rendered at the root level for example: + +It could be achieved by a `render()` method like this: + +```tsx +@Component({tag: 'my-cmp'}) +export class MyCmp { + render() { + return ( + +

Title

+

Message

+
+ ); + } +} +``` + +This JSX would render the following HTML: + +```markup + +

Title

+

Message

+
+``` + +Even if we don't use `` to render any attribute in the host element, it's a useful API to render many elements at the root level. + +## Element Decorator + +The `@Element()` decorator is how to get access to the host element within the class instance. This returns an instance of an `HTMLElement`, so standard DOM methods/events can be used here. + +```tsx +import { Element } from '@stencil/core'; + +... +export class TodoList { + + @Element() el: HTMLElement; + + getListHeight(): number { + return this.el.getBoundingClientRect().height; + } +} +``` + +In order to reference the host element when initializing a class member you'll need to use TypeScript's definite assignment assertion modifier to avoid a +type error: + +```tsx +import { Element } from '@stencil/core'; + +... +export class TodoList { + + @Element() el!: HTMLElement; + + private listHeight = this.el.getBoundingClientRect().height; +} +``` + +If you need to update the host element in response to prop or state changes, you should do so in the `render()` method using the `` element. + +## Styling + +See full information about styling on the [Styling page](./styling.md#shadow-dom-in-stencil). + +CSS can be applied to the `` element by using its component tag defined in the `@Component` decorator. + +```tsx +@Component({ + tag: 'my-cmp', + styleUrl: 'my-cmp.css' +}) +... +``` + +my-cmp.css: + +```css +my-cmp { + width: 100px; +} +``` + +### Shadow DOM + +Something to beware of is that Styling the `` element when using shadow DOM does not work quite the same. Instead of using the `my-cmp` element selector you must use `:host`. + +```tsx +@Component({ + tag: 'my-cmp', + styleUrl: 'my-cmp.css', + shadow: true +}) +... +``` + +my-cmp.css: + +```css +:host { + width: 100px; +} +``` diff --git a/versioned_docs/version-v4.18/components/methods.md b/versioned_docs/version-v4.18/components/methods.md new file mode 100644 index 000000000..931839b91 --- /dev/null +++ b/versioned_docs/version-v4.18/components/methods.md @@ -0,0 +1,98 @@ +--- +title: Methods +sidebar_label: Methods +description: methods +slug: /methods +--- + +# Method Decorator + +The `@Method()` decorator is used to expose methods on the public API. Functions decorated with the `@Method()` decorator can be called directly from the element, i.e. they are intended to be callable from the outside! + +:::note +Developers should try to rely on publicly exposed methods as little as possible, and instead default to using properties and events as much as possible. As an app scales, we've found it's easier to manage and pass data through @Prop rather than public methods. +::: + +```tsx +import { Method } from '@stencil/core'; + +export class TodoList { + + @Method() + async showPrompt() { + // show a prompt + } +} +``` + +Call the method like this: + +:::note +Developers should ensure that the component is defined by using the whenDefined method of the custom element registry before attempting to call public methods. +::: + +```tsx +(async () => { + await customElements.whenDefined('todo-list'); + const todoListElement = document.querySelector('todo-list'); + await todoListElement.showPrompt(); +})(); +``` + +## Public methods must be async + +Stencil's architecture is async at all levels which allows for many performance benefits and ease of use. By ensuring publicly exposed methods using the `@Method` decorator return a promise: + +- Developers can call methods before the implementation was downloaded without componentOnReady(), which queues the method calls and resolves after the component has finished loading. + +- Interaction with the component is the same whether it still needs to be lazy-loaded, or is already fully hydrated. + +- By keeping a component's public API async, apps could move the components transparently to [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) and the API would still be the same. + +- Returning a promise is only required for publicly exposed methods which have the `@Method` decorator. All other component methods are private to the component and are not required to be async. + + +```tsx +// VALID: using async +@Method() +async myMethod() { + return 42; +} + +// VALID: using Promise.resolve() +@Method() +myMethod2() { + return Promise.resolve(42); +} + +// VALID: even if it returns nothing, it needs to be async +@Method() +async myMethod3() { + console.log(42); +} + +// INVALID +@Method() +notOk() { + return 42; +} +``` + +## Private methods + +Non-public methods can still be used to organize the business logic of your component and they do NOT have to return a Promise. + +```tsx +class Component { + // Since `getData` is not a public method exposed with @Method + // it does not need to be async + getData() { + return this.someData; + } + render() { + return ( +
{this.getData()}
+ ); + } +} +``` diff --git a/versioned_docs/version-v4.18/components/properties.md b/versioned_docs/version-v4.18/components/properties.md new file mode 100644 index 000000000..c0855b350 --- /dev/null +++ b/versioned_docs/version-v4.18/components/properties.md @@ -0,0 +1,974 @@ +--- +title: Properties +sidebar_label: Properties +description: Properties +slug: /properties +--- + +# Properties + +Props are custom attributes/properties exposed publicly on an HTML element. They allow developers to pass data to a +component to render or otherwise use. + +## The Prop Decorator (`@Prop()`) + +Props are declared on a component using Stencil's `@Prop()` decorator, like so: + +```tsx +// First, we import Prop from '@stencil/core' +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list', +}) +export class TodoList { + // Second, we decorate a class member with @Prop() + @Prop() name: string; + + render() { + // Within the component's class, its props are + // accessed via `this`. This allows us to render + // the value passed to `todo-list` + return
To-Do List Name: {this.name}
+ } +} +``` + +In the example above, `@Prop()` is placed before (decorates) the `name` class member, which is a string. By adding +`@Prop()` to `name`, Stencil will expose `name` as an attribute on the element, which can be set wherever the component +is used: + +```tsx +{/* Here we use the component in a TSX file */} + +``` +```html + + +``` + +In the example above the `todo-list` component is used almost identically in TSX and HTML. The only difference between +the two is that in TSX, the value assigned to a prop (in this case, `name`) is wrapped in curly braces. In some cases +however, the way props are passed to a component differs slightly between HTML and TSX. + +## Variable Casing + +In the JavaScript ecosystem, it's common to use 'camelCase' when naming variables. The example component below has a +class member, `thingToDo` that is camelCased. + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + // thingToDo is 'camelCased' + @Prop() thingToDo: string; + + render() { + return
{this.thingToDo}
; + } +} +``` + +Since `thingToDo` is a prop, we can provide a value for it when we use our `todo-list-item` component. Providing a +value to a camelCased prop like `thingToDo` is nearly identical in TSX and HTML. + +When we use our component in a TSX file, an attribute uses camelCase: + +```tsx + +``` + +In HTML, the attribute must use 'dash-case' like so: + +```html + +``` + +## Data Flow + +Props should be used to pass data down from a parent component to its child component(s). + +The example below shows how a `todo-list` component uses three `todo-list-item` child components to render a ToDo list. + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list', +}) +export class TodoList { + render() { + return ( +
+

To-Do List Name: Stencil To Do List

+
    + {/* Below are three Stencil components that are children of `todo-list`, each representing an item on our list */} + + + +
+
+ ) + } +} +``` +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() thingToDo: string; + + render() { + return
  • {this.thingToDo}
  • ; + } +} +``` + +:::note +Children components should not know about or reference their parent components. This allows Stencil to +efficiently re-render your components. Passing a reference to a component as a prop may cause unintended side effects. +::: + +## Mutability + +A Prop is by default immutable from inside the component logic. Once a value is set by a user, the component cannot +update it internally. For more advanced control over the mutability of a prop, please see the +[mutable option](#prop-mutability-mutable) section of this document. + +## Types + +Props can be a `boolean`, `number`, `string`, or even an `Object` or `Array`. The example below expands the +`todo-list-item` to add a few more props with different types. + +```tsx +import { Component, Prop, h } from '@stencil/core'; +// `MyHttpService` is an `Object` in this example +import { MyHttpService } from '../some/local/directory/MyHttpService'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() isComplete: boolean; + @Prop() timesCompletedInPast: number; + @Prop() thingToDo: string; + @Prop() myHttpService: MyHttpService; +} +``` + +### Boolean Props + +A property on a Stencil component that has a type of `boolean` may be declared as: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() isComplete: boolean; +} +``` + +To use this version of `todo-list-item` in HTML, we pass the string `"true"`/`"false"` to the component: +```html + + + + +``` + +To use this version of `todo-list-item` in TSX, `true`/`false` is used, surrounded by curly braces: +```tsx +// Set isComplete to 'true' + +// Set isComplete to 'false' + +``` + +There are a few ways in which Stencil treats props that are of type `boolean` that are worth noting: + +1. The value of a boolean prop will be `false` if provided the string `"false"` in HTML + +```html + + +``` +2. The value of a boolean prop will be `true` if provided a string that is not `"false"` in HTML + +```html + + + + + +``` +3. The value of a boolean prop will be `undefined` if it has no [default value](#default-values) and one of +the following applies: + 1. the prop is not included when using the component + 2. the prop is included when using the component, but is not given a value + +```html + + + + +``` + +### Number Props + +A property on a Stencil component that has a type of `number` may be declared as: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() timesCompletedInPast: number; +} +``` + +To use this version of `todo-list-item` in HTML, we pass the numeric value as a string to the component: +```html + + + + +``` + +To use this version of `todo-list-item` in TSX, a number surrounded by curly braces is passed to the component: +```tsx +// Set timesCompletedInPast to '0' + +// Set timesCompletedInPast to '23' + +``` + +### String Props + +A property on a Stencil component that has a type of `string` may be declared as: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() thingToDo: string; +} +``` + +To use this version of `todo-list-item` in HTML, we pass the value as a string to the component: +```html + + + + +``` + +To use this version of `todo-list-item` in TSX, we pass the value as a string to the component. Curly braces aren't +required when providing string values to props in TSX, but are permitted: +```tsx +// Set thingToDo to 'Learn about Stencil Props' + +// Set thingToDo to 'Write some Stencil Code with Props' + +// Set thingToDo to 'Write some Stencil Code with Props' with curly braces + +``` + +### Object Props + +A property on a Stencil component that has a type of `Object` may be declared as: + +```tsx +// TodoListItem.tsx +import { Component, Prop, h } from '@stencil/core'; +import { MyHttpService } from '../path/to/MyHttpService'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + // Use `@Prop()` to declare the `httpService` class member + @Prop() httpService: MyHttpService; +} +``` +```tsx +// MyHttpService.ts +export class MyHttpService { + // This implementation intentionally left blank +} +``` + +In TypeScript, `MyHttpService` is both an `Object` and a 'type'. When using user-defined types like `MyHttpService`, the +type must always be exported using the `export` keyword where it is declared. The reason for this is Stencil needs to +know what type the prop `httpService` is when passing an instance of `MyHttpService` to `TodoListItem` from a parent +component. + +To set `httpService` in TSX, assign the property name in the custom element's tag to the desired value like so: +```tsx +// TodoList.tsx +import { Component, h } from '@stencil/core'; +import { MyHttpService } from '../MyHttpService'; + +@Component({ + tag: 'todo-list', + styleUrl: 'todo-list.css', + shadow: true, +}) +export class ToDoList { + private httpService = new MyHttpService(); + + render() { + return ; + } +} +``` +Note that the prop name is using `camelCase`, and the value is surrounded by curly braces. + +It is not possible to set `Object` props via an HTML attribute like so: +```html + + +``` +The reason for this is that Stencil will not attempt to serialize object-like strings written in HTML into a JavaScript object. +Similarly, Stencil does not have any support for deserializing objects from JSON. +Doing either can be expensive at runtime, and runs the risk of losing references to other nested JavaScript objects. + +Instead, properties may be set via ` +``` + + +### Array Props + +A property on a Stencil component that is an Array may be declared as: + +```tsx +// TodoList.tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() itemLabels: string[]; +} +``` + +To set `itemLabels` in TSX, assign the prop name in the custom element's tag to the desired value like so: +```tsx +// TodoList.tsx +import { Component, h } from '@stencil/core'; +import { MyHttpService } from '../MyHttpService'; + +@Component({ + tag: 'todo-list', + styleUrl: 'todo-list.css', + shadow: true, +}) +export class ToDoList { + private labels = ['non-urgent', 'weekend-only']; + + render() { + return ; + } +} +``` +Note that the prop name is using `camelCase`, and the value is surrounded by curly braces. + +It is not possible to set `Array` props via an HTML attribute like so: +```html + + +``` +The reason for this is that Stencil will not attempt to serialize array-like strings written in HTML into a JavaScript object. +Doing so can be expensive at runtime, and runs the risk of losing references to other nested JavaScript objects. + +Instead, properties may be set via ` +``` + +### Advanced Prop Types + +#### `any` Type + +TypeScript's [`any` type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any) is a special type +that may be used to prevent type checking of a specific value. Because `any` is a valid type in TypeScript, Stencil +props can also be given a type of `any`. The example below demonstrates three different ways of using props with type +`any`: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + // isComplete has an explicit type annotation + // of `any`, and no default value + @Prop() isComplete: any; + // label has an explicit type annotation of + // `any` with a default value of 'urgent', + // which is a string + @Prop() label: any = 'urgent'; + // thingToDo has no type and no default value, + // and will be considered to be type `any` by + // TypeScript + @Prop() thingToDo; + + render() { + return ( +
      +
    • isComplete has a value of - {this.isComplete} - and a typeof value of "{typeof this.isComplete}"
    • +
    • label has a value of - {this.label} - and a typeof value of "{typeof this.label}"
    • +
    • thingToDo has a value of - {this.thingToDo} - and a typeof value of "{typeof this.thingToDo}"
    • +
    + ); + } +} +``` + +When using a Stencil prop typed as `any` (implicitly or explicitly), the value that is provided to a prop retains its +own type information. Neither Stencil nor TypeScript will try to change the type of the prop. To demonstrate, let's use +`todo-list-item` twice, each with different prop values: + +```tsx +{/* Using todo-list-item in TSX using differnt values each time */} + + +``` + +The following will rendered from the usage example above: +```md +- isComplete has a value of - 42 - and a typeof value of "number" +- label has a value of - - and a typeof value of "object" +- thingToDo has a value of - Learn about any-typed props - and a typeof value of "string" + +- isComplete has a value of - 42 - and a typeof value of "string" +- label has a value of - 1 - and a typeof value of "number" +- thingToDo has a value of - Learn about any-typed props - and a typeof value of "string" +``` + +In the first usage of `todo-list-item`, `isComplete` is provided a number value of 42, whereas in the second usage it +receives a string containing "42". The types on `isComplete` reflect the type of the value it was provided, 'number' and +'string', respectively. + +Looking at `label`, it is worth noting that although the prop has a [default value](#default-values), it does +not narrow the type of `label` to be of type 'string'. In the first usage of `todo-list-item`, `label` is provided a +value of null, whereas in the second usage it receives a number value of 1. The types of the values stored in `label` +are correctly reported as 'object' and 'number', respectively. + +#### Optional Types + +TypeScript allows members to be marked optional by appending a `?` at the end of the member's name. The example below +demonstrates making each a component's props optional: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + // completeMsg is optional, has an explicit type + // annotation of `string`, and no default value + @Prop() completeMsg?: string; + // label is optional, has no explicit type + // annotation, but does have a default value + // of 'urgent' + @Prop() label? = 'urgent'; + // thingToDo has no type annotation and no + // default value + @Prop() thingToDo?; + + render() { + return ( +
      +
    • completeMsg has a value of - {this.completeMsg} - and a typeof value of "{typeof this.completeMsg}"
    • +
    • label has a value of - {this.label} - and a typeof value of "{typeof this.label}"
    • +
    • thingToDo has a value of - {this.thingToDo} - and a typeof value of "{typeof this.thingToDo}"
    • +
    + ); + } +} +``` + +When using a Stencil prop that is marked as optional, Stencil will try to infer the type of the prop if a type is +not explicitly given. In the example above, Stencil is able to understand that: + +- `completeMsg` is of type string, because it has an explicit type annotation +- `label` is of type string, because it has a [default value](#default-values) that is of type string +- `thingToDo` [is of type `any`](#any-type), because it has no explicit type annotation, nor default value + +Because Stencil can infer the type of `label`, the following will fail to compile due to a type mismatch: + +```tsx +{/* This fails to compile with the error "Type 'number' is not assignable to type 'string'" for the label prop. */} + +``` + +It is worth noting that when using a component in an HTML file, such type checking is unavailable. This is a constraint +on HTML, where all values provided to attributes are of type string: + +```html + + +``` +renders: +```md +- completeMsg has a value of - 42 - and a typeof value of "string" +- label has a value of - null - and a typeof value of "string" +- thingToDo has a value of - Learn about any-typed props - and a typeof value of "string" +``` + +#### Union Types + +Stencil allows props types be [union types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types), +which allows you as the developer to combine two or more pre-existing types to create a new one. The example below shows +a `todo-list-item` who accepts a `isComplete` prop that can be either a string or boolean. + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() isComplete: string | boolean; +} +``` + +This component can be used in both HTML: +```html + + + + +``` +and TSX: +```tsx + + +``` + +When using union types, the type of a component's `@Prop()` value can be ambiguous at runtime. +In the provided example, under what circumstances does `@Prop() isComplete` function as a `string`, and when does it serve as a `boolean`? + +When using a component in HTML, the runtime value of a `@Prop()` is a string whenever an attribute is set. +This is a result of setting the HTML attribute for the custom element. +```html + + + + + + + + +``` +However, if an attribute is not specified, the runtime value of the property will be `undefined`: +```html + + +``` + +When the attribute on a component is set using `setAttribute`, the runtime value of a `@Prop()` is always [coerced to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion). +```html + +``` + +However, if the property of a custom element is directly changed, its type will match the value that was provided. +```html + +``` + +When using a component in TSX, a `@Prop()`'s type will match the value that was provided. +```tsx +// Since this is TSX, the value of `isComplete` in `ToDoListItem` +// depends on the type of the value passed to the component. +// +// Set the property `isComplete` to `true` (boolean) + +// Set the property `isComplete` to "true" (string) + +// Set the property `isComplete` to `false` (boolean) + +// Set the property `isComplete` to "false" (string) + +``` + +## Default Values + +Stencil props can be given a default value as a fallback in the event a prop is not provided: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'component-with-some-props', +}) +export class ComponentWithSomeProps { + @Prop() aNumber = 42; + @Prop() aString = 'defaultValue'; + + render() { + return
    The number is {this.aNumber} and the string is {this.aString}
    + } +} +``` +Regardless of if we use this component in HTML or TSX, "The number is 42 and the string is defaultValue" is displayed +when no values are passed to our component: +```html + +``` + +The default values on a component can be overridden by specifying a value for a prop with a default value. For the +example below, "The number is 7 and the string is defaultValue" is rendered. Note how the value provided to `aNumber` +overrides the default value, but the default value of `aString` remains the same: +```html + +``` + +### Inferring Types from Default Values + +When a default value is provided, Stencil is able to infer the type of the prop from the default value: + +```tsx +import { Component, Prop, h } from '@stencil/core'; +@Component({ + tag: 'component-with-many-props', +}) +export class ComponentWithManyProps { + // both props below are of type 'boolean' + @Prop() boolean1: boolean; + @Prop() boolean2 = true; + + // both props below are of type 'number' + @Prop() number1: number; + @Prop() number2 = 42; + + // both props below are of type 'string' + @Prop() string1: string; + @Prop() string2 = 'defaultValue'; +} +``` + +## Required Properties + +By placing a `!` after a prop name, Stencil mark that the attribute/property as required. This ensures that when the +component is used in TSX, the property is used: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + // Note the '!' after the variable name. + @Prop() thingToDo!: string; +} +``` + +## Prop Validation + +To do validation of a Prop, you can use the [@Watch()](./reactive-data.md#the-watch-decorator-watch) decorator: + +```tsx +import { Component, Prop, Watch, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class TodoList { + // Mark the prop as required, to make sure it is provided when we use `todo-list-item`. + // We want stricter guarantees around the contents of the string, so we'll use `@Watch` to perform additional validation. + @Prop() thingToDo!: string; + + @Watch('thingToDo') + validateName(newValue: string, _oldValue: string) { + // don't allow `thingToDo` to be the empty string + const isBlank = typeof newValue !== 'string' || newValue === ''; + if (isBlank) { + throw new Error('thingToDo is a required property and cannot be empty') + }; + // don't allow `thingToDo` to be a string with a length of 1 + const has2chars = typeof newValue === 'string' && newValue.length >= 2; + if (!has2chars) { + throw new Error('thingToDo must have a length of more than 1 character') + }; + } +} +``` + +## @Prop() Options + +The `@Prop()` decorator accepts an optional argument to specify certain options to modify how a prop on a component +behaves. `@Prop()`'s optional argument is an object literal containing one or more of the following fields: + +```tsx +export interface PropOptions { + attribute?: string; + mutable?: boolean; + reflect?: boolean; +} +``` + +### Attribute Name (`attribute`) + +Properties and component attributes are strongly connected but not necessarily the same thing. While attributes are an +HTML concept, properties are a JavaScript concept inherent to Object-Oriented Programming. + +In Stencil, the `@Prop()` decorator applied to a **property** will instruct the Stencil compiler to also listen for +changes in a DOM attribute. + +Usually, the name of a property is the same as the attribute, but this is not always the case. Take the following +component as example: + +```tsx +import { Component, Prop, h } from '@stencil/core'; +// `MyHttpService` is an `Object` in this example +import { MyHttpService } from '../some/local/directory/MyHttpService'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop() isComplete: boolean; + @Prop() thingToDo: string; + @Prop() httpService: MyHttpService; +} +``` + +This component has **3 properties**, but the compiler will create **only 2 attributes**: `is-complete` and +`thing-to-do`. + +```html + +``` + +Notice that the `httpService` type is not a primitive (e.g. not a `number`, `boolean`, or `string`). Since DOM +attributes can only be strings, it does not make sense to have an associated DOM attribute called `"http-service"`. +Stencil will not attempt to serialize object-like strings written in HTML into a JavaScript object. +See [Object Props](#object-props) for guidance as to how to configure `httpService`. + +At the same time, the `isComplete` & `thingToDo` properties follow 'camelCase' naming, but attributes are +case-insensitive, so the attribute names will be `is-complete` & `thing-to-do` by default. + +Fortunately, this "default" behavior can be changed using the `attribute` option of the `@Prop()` decorator: + +```tsx +import { Component, Prop, h } from '@stencil/core'; +// `MyHttpService` is an `Object` in this example +import { MyHttpService } from '../some/local/directory/MyHttpService'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop({ attribute: 'complete' }) isComplete: boolean; + @Prop({ attribute: 'thing' }) thingToDo: string; + @Prop({ attribute: 'my-service' }) httpService: MyHttpService; +} +``` + +By using this option, we are being explicit about which properties have an associated DOM attribute and the name of it +when using the component in HTML. + +```html + +``` + +### Prop Mutability (`mutable`) + +A Prop is by default immutable from inside the component logic. +However, it's possible to explicitly allow a Prop to be mutated from inside the component, by declaring it as mutable, as in the example below: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop({ mutable: true }) thingToDo: string; + + componentDidLoad() { + this.thingToDo = 'Ah! A new value!'; + } +} +``` + +#### Mutable Arrays and Objects + +Stencil compares Props by reference in order to efficiently rerender components. +Setting `mutable: true` on a Prop that is an object or array allows the _reference_ to the Prop to change inside the component and trigger a render. +It does not allow a mutable change to an existing object or array to trigger a render. + +For example, to update an array Prop: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'my-component', +}) +export class MyComponent { + @Prop({mutable: true}) contents: string[] = []; + timer: NodeJS.Timer; + + connectedCallback() { + this.timer = setTimeout(() => { + // this does not create a new array. when stencil + // attempts to see if any of its Props have changed, + // it sees the reference to its `contents` Prop is + // the same, and will not trigger a render + + // this.contents.push('Stencil') + + // this does create a new array, and therefore a + // new reference to the Prop. Stencil will pick up + // this change and rerender + this.contents = [...this.contents, 'Stencil']; + // after 3 seconds, the component will re-render due + // to the reference change in `this.contents` + }, 3000); + } + + disconnectedCallback() { + if (this.timer) { + clearTimeout(this.timer); + } + } + + render() { + return
    Hello, World! I'm {this.contents[0]}
    ; + } +} +``` + +In the example above, updating the Prop in place using `this.contents.push('Stencil')` would have no effect. +Stencil does not see the change to `this.contents`, since it looks at the _reference_ of the Prop, and sees that it has not changed. +This is done for performance reasons. +If Stencil had to walk every slot of the array to determine if it changed, it would incur a performance hit. +Rather, it is considered better for performance and more idiomatic to re-assign the Prop (in the example above, we use the spread operator). + +The same holds for objects as well. +Rather than mutating an existing object in-place, a new object should be created using the spread operator. This object will be different-by-reference and therefore will trigger a re-render: + + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +export type MyContents = {name: string}; + +@Component({ + tag: 'my-component', +}) +export class MyComponent { + @Prop({mutable: true}) contents: MyContents; + timer: NodeJS.Timer; + + connectedCallback() { + this.timer = setTimeout(() => { + // this does not create a new object. when stencil + // attempts to see if any of its Props have changed, + // it sees the reference to its `contents` Prop is + // the same, and will not trigger a render + + // this.contents.name = 'Stencil'; + + // this does create a new object, and therefore a + // new reference to the Prop. Stencil will pick up + // this change and rerender + this.contents = {...this.contents, name: 'Stencil'}; + // after 3 seconds, the component will re-render due + // to the reference change in `this.contents` + }, 3000); + } + + disconnectedCallback() { + if (this.timer) { + clearTimeout(this.timer); + } + } + + render() { + return
    Hello, World! I'm {this.contents.name}
    ; + } +} +``` + +### Reflect Properties Values to Attributes (`reflect`) + +In some cases it may be useful to keep a Prop in sync with an attribute. In this case you can set the `reflect` option +in the `@Prop()` decorator to `true`. When a prop is reflected, it will be rendered in the DOM as an HTML attribute. + +Take the following component as example: + +```tsx +import { Component, Prop, h } from '@stencil/core'; + +@Component({ + tag: 'todo-list-item', +}) +export class ToDoListItem { + @Prop({ reflect: false }) isComplete: boolean = false; + @Prop({ reflect: true }) timesCompletedInPast: number = 2; + @Prop({ reflect: true }) thingToDo: string = "Read Reflect Section of Stencil Docs"; +} +``` + +The component in the example above uses [default values](#default-values), and can be used in HTML like so: +```html + + +``` + +When rendered in the DOM, the properties configured with `reflect: true` will be reflected in the DOM: + +```html + +``` + +While the properties not set to "reflect", such as `isComplete`, are not rendered as attributes, it does not mean it's +not there - the `isComplete` property still contains the `false` value as assigned: + +```tsx +const cmp = document.querySelector('todo-list-item'); +console.log(cmp.isComplete); // it prints 'false' +``` diff --git a/versioned_docs/version-v4.18/components/reactive-data.md b/versioned_docs/version-v4.18/components/reactive-data.md new file mode 100644 index 000000000..b41db4c12 --- /dev/null +++ b/versioned_docs/version-v4.18/components/reactive-data.md @@ -0,0 +1,248 @@ +--- +title: Reactive Data, Handling arrays and objects +sidebar_label: Reactive Data +description: Reactive Data, Handling arrays and objects +slug: /reactive-data +--- + +# Reactive Data + +Stencil components update when props or state on a component change. + +## Rendering methods + +When props or state change on a component, the [`render()` method](./templating-and-jsx.md) is scheduled to run. + +## The Watch Decorator (`@Watch()`) + +`@Watch()` is a decorator that is applied to a method of a Stencil component. +The decorator accepts a single argument, the name of a class member that is decorated with `@Prop()` or `@State()`, or +a host attribute. A method decorated with `@Watch()` will automatically run when its associated class member or attribute changes. + +```tsx +// We import Prop & State to show how `@Watch()` can be used on +// class members decorated with either `@Prop()` or `@State()` +import { Component, Prop, State, Watch } from '@stencil/core'; + +@Component({ + tag: 'loading-indicator' +}) +export class LoadingIndicator { + // We decorate a class member with @Prop() so that we + // can apply @Watch() + @Prop() activated: boolean; + // We decorate a class member with @State() so that we + // can apply @Watch() + @State() busy: boolean; + + // Apply @Watch() for the component's `activated` member. + // Whenever `activated` changes, this method will fire. + @Watch('activated') + watchPropHandler(newValue: boolean, oldValue: boolean) { + console.log('The old value of activated is: ', oldValue); + console.log('The new value of activated is: ', newValue); + } + + // Apply @Watch() for the component's `busy` member. + // Whenever `busy` changes, this method will fire. + @Watch('busy') + watchStateHandler(newValue: boolean, oldValue: boolean) { + console.log('The old value of busy is: ', oldValue); + console.log('The new value of busy is: ', newValue); + } + + @Watch('activated') + @Watch('busy') + watchMultiple(newValue: boolean, oldValue: boolean, propName:string) { + console.log(`The new value of ${propName} is: `, newValue); + } +} +``` + +In the example above, there are two `@Watch()` decorators. +One decorates `watchPropHandler`, which will fire when the class member `activated` changes. +The other decorates `watchStateHandler`, which will fire when the class member `busy` changes. + +When fired, the decorated method will receive the old and new values of the prop/state. +This is useful for validation or the handling of side effects. + +:::info +The `@Watch()` decorator does not fire when a component initially loads. +::: + +### Watching Native HTML Attributes + +Stencil's `@Watch()` decorator also allows you to watch native HTML attributes on the constructed host element. Simply +include the attribute name as the argument to the decorator (this is case-sensitive): + +```tsx +@Watch('aria-label') +onAriaLabelChange(newVal: string, oldVal: string) { + console.log('Label changed:', newVal, oldVal); +} +``` + +:::note +Since native attributes are not `@Prop()` or `State()` members of the Stencil component, they will not automatically trigger a +re-render when changed. If you wish to re-render a component in this instance, you can leverage the `forceUpdate()` method: + +```tsx +import { Component, forceUpdate, h } from '@stencil/core'; + +@Watch('aria-label') +onAriaLabelChange() { + forceUpdate(this); // Forces a re-render +} +``` +::: + +## Handling Arrays and Objects + +When Stencil checks if a class member decorated with `@Prop()` or `@State()` has changed, it checks if the reference to the class member has changed. +When a class member is an object or array, and is marked with `@Prop()` or `@State`, in-place mutation of an existing entity will _not_ cause `@Watch()` to fire, as it does not change the _reference_ to the class member. + +### Updating Arrays + +For arrays, the standard mutable array operations such as `push()` and `unshift()` won't trigger a component update. +These functions will change the content of the array, but won't change the reference to the array itself. + +In order to make changes to an array, non-mutable array operators should be used. +Non-mutable array operators return a copy of a new array that can be detected in a performant manner. +These include `map()` and `filter()`, and the [spread operator syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator). +The value returned by `map()`, `filter()`, etc., should be assigned to the `@Prop()` or `@State()` class member being watched. + +For example, to push a new item to an array, create a new array with the existing values and the new value at the end: + +```tsx +import { Component, State, Watch, h } from '@stencil/core'; + +@Component({ + tag: 'rand-numbers' +}) +export class RandomNumbers { + // We decorate a class member with @State() so that we + // can apply @Watch(). This will hold a list of randomly + // generated numbers + @State() randNumbers: number[] = []; + + private timer: NodeJS.Timer; + + // Apply @Watch() for the component's `randNumbers` member. + // Whenever `randNumbers` changes, this method will fire. + @Watch('randNumbers') + watchStateHandler(newValue: number[], oldValue: number[]) { + console.log('The old value of randNumbers is: ', oldValue); + console.log('The new value of randNumbers is: ', newValue); + } + + connectedCallback() { + this.timer = setInterval(() => { + // generate a random whole number + const newVal = Math.ceil(Math.random() * 100); + + /** + * This does not create a new array. When stencil + * attempts to see if any Watched members have changed, + * it sees the reference to its `randNumbers` State is + * the same, and will not trigger `@Watch` or a re-render + */ + // this.randNumbers.push(newVal) + + /** + * Using the spread operator, on the other hand, does + * create a new array. `randNumbers` is reassigned + * using the value returned by the spread operator. + * The reference to `randNumbers` has changed, which + * will trigger `@Watch` and a re-render + */ + this.randNumbers = [...this.randNumbers, newVal] + }, 1000) + } + + disconnectedCallback() { + if (this.timer) { + clearInterval(this.timer) + } + } + + render() { + return( +
    + randNumbers contains: +
      + {this.randNumbers.map((num) =>
    1. {num}
    2. )} +
    +
    + ) + } +} +``` + +### Updating an object + +The spread operator should be used to update objects. +As with arrays, mutating an object will not trigger a view update in Stencil. +However, using the spread operator and assigning its return value to the `@Prop()` or `@State()` class member being watched will. +Below is an example: + +```tsx +import { Component, State, Watch, h } from '@stencil/core'; + +export type NumberContainer = { + val: number, +} + +@Component({ + tag: 'rand-numbers' +}) +export class RandomNumbers { + // We decorate a class member with @State() so that we + // can apply @Watch(). This will hold a randomly generated + // number. + @State() numberContainer: NumberContainer = { val: 0 }; + + private timer: NodeJS.Timer; + + // Apply @Watch() for the component's `numberContainer` member. + // Whenever `numberContainer` changes, this method will fire. + @Watch('numberContainer') + watchStateHandler(newValue: NumberContainer, oldValue: NumberContainer) { + console.log('The old value of numberContainer is: ', oldValue); + console.log('The new value of numberContainer is: ', newValue); + } + + connectedCallback() { + this.timer = setInterval(() => { + // generate a random whole number + const newVal = Math.ceil(Math.random() * 100); + + /** + * This does not create a new object. When stencil + * attempts to see if any Watched members have changed, + * it sees the reference to its `numberContainer` State is + * the same, and will not trigger `@Watch` or are-render + */ + // this.numberContainer.val = newVal; + + /** + * Using the spread operator, on the other hand, does + * create a new object. `numberContainer` is reassigned + * using the value returned by the spread operator. + * The reference to `numberContainer` has changed, which + * will trigger `@Watch` and a re-render + */ + this.numberContainer = {...this.numberContainer, val: newVal}; + }, 1000) + } + + disconnectedCallback() { + if (this.timer) { + clearInterval(this.timer) + } + } + + render() { + return
    numberContainer contains: {this.numberContainer.val}
    ; + } +} +``` diff --git a/versioned_docs/version-v4.18/components/state.md b/versioned_docs/version-v4.18/components/state.md new file mode 100644 index 000000000..5a78b0447 --- /dev/null +++ b/versioned_docs/version-v4.18/components/state.md @@ -0,0 +1,265 @@ +--- +title: Internal state +sidebar_label: Internal State +description: Use the State() for component's internal state +slug: /state +--- + +# State + +'State' is a general term that refers to the values and objects that are stored on a class or an instance of a class for +use now or in the future. + +Like a regular TypeScript class, a Stencil component may have one or more internal class members for holding value(s) +that make up the component's state. Stencil allows developers to optionally mark class members holding some part of the +class's state with the `@State()` decorator to trigger a rerender when the state changes. + +## The State Decorator (`@State`) + +Stencil provides a decorator to trigger a rerender when certain class members change. A component's class members that +should trigger a rerender must be decorated using Stencil's `@State()` decorator, like so: +```tsx +// First, we import State from '@stencil/core' +import { Component, State, h } from '@stencil/core'; + +@Component({ + tag: 'current-time', +}) +export class CurrentTime { + // Second, we decorate a class member with @State() + // When `currentTime` changes, a rerender will be + // triggered + @State() currentTime: number = Date.now(); + + render() { + // Within the component's class, its members are + // accessed via `this`. This allows us to render + // the value stored in `currentTime` + const time = new Date(this.currentTime).toLocaleTimeString(); + + return ( + {time} + ); + } +} +``` + +In the example above, `@State()` is placed before (decorates) the `currentTime` class member, which is a number. This +marks `currentTime` so that any time its value changes, the component rerenders. + +However, the example above doesn't demonstrate the real power of using `@State`. `@State` members are meant to only be +updated within a class, which the example above never does after the initial assignment of `currentTime`. This means +that our `current-time` component will never rerender! We fix that in the example below to update `current-time` every +1000 milliseconds (1 second): + +```tsx +import { Component, State, h } from '@stencil/core'; + +@Component({ + tag: 'current-time', +}) +export class CurrentTime { + timer: number; + + // `currentTime` is decorated with `@State()`, + // as we need to trigger a rerender when its + // value changes to show the latest time + @State() currentTime: number = Date.now(); + + connectedCallback() { + this.timer = window.setInterval(() => { + // the assignment to `this.currentTime` + // will trigger a re-render + this.currentTime = Date.now(); + }, 1000); + } + + disconnectedCallback() { + window.clearInterval(this.timer); + } + + render() { + const time = new Date(this.currentTime).toLocaleTimeString(); + + return ( + {time} + ); + } +} +``` + +The example above makes use of the [connectedCallback() lifecycle method](./component-lifecycle.md#connectedcallback) +to set `currentTime` to the value of `Date.now()` every 1000 milliseconds (or, every one second). Because the value of +`currentTime` changes every second, Stencil calls the `render` function on `current-time`, which pretty-prints the +current time. + +The example above also makes use of the +[disconnectedCallback() lifecycle method](./component-lifecycle.md#disconnectedcallback) to properly clean up the timer +that was created using `setInterval` in `connectedCallback()`. This isn't necessary for using `@State`, but is a general +good practice when using `setInterval`. + +## When to Use `@State()`? + +`@State()` should be used for all class members that should trigger a rerender when they change. However, not all +internal state might need to be decorated with `@State()`. If you know for sure that the value will either not change or +that it does not need to trigger a re-rendering, `@State()` is not necessary. It is considered a 'best practice' to +only use `@State()` when absolutely necessary. Revisiting our `current-time` component: + +```tsx +import { Component, State, h } from '@stencil/core'; + +@Component({ + tag: 'current-time', +}) +export class CurrentTime { + // `timer` is not decorated with `@State()`, as + // we do not wish to trigger a rerender when its + // value changes + timer: number; + + // `currentTime` is decorated with `@State()`, + // as we need to trigger a rerender when its + // value changes to show the latest time + @State() currentTime: number = Date.now(); + + connectedCallback() { + // the assignment to `this.timer` will not + // trigger a re-render + this.timer = window.setInterval(() => { + // the assignment to `this.currentTime` + // will trigger a re-render + this.currentTime = Date.now(); + }, 1000); + } + + disconnectedCallback() { + window.clearInterval(this.timer); + } + + render() { + const time = new Date(this.currentTime).toLocaleTimeString(); + + return ( + {time} + ); + } +} +``` + +## Examples + +### Using `@State()` with `@Listen()` + +This example makes use of `@State` and [`@Listen`](./events.md#listen-decorator) decorators. We define a class member +called `isOpen` and decorate it with `@State()`. With the use of `@Listen()`, we respond to click events toggling the +value of `isOpen`. + +```tsx +import { Component, Listen, State, h } from '@stencil/core'; + +@Component({ + tag: 'my-toggle-button' +}) +export class MyToggleButton { + // `isOpen` is decorated with `@State()`, + // changes to it will trigger a rerender + @State() isOpen: boolean = true; + + @Listen('click', { capture: true }) + handleClick() { + // whenever a click event occurs on + // the component, update `isOpen`, + // triggering the rerender + this.isOpen = !this.isOpen; + } + + render() { + return ; + } +} +``` + +### Complex Types + +For more advanced use cases, `@State()` can be used with a complex type. In the example below, we print a list of `Item` +entries. Although we start with zero `Item`s initially, we use the same pattern as we did before to add a new `Item` to +`ItemList`'s `items` array once every 2000 milliseconds (2 seconds). Every time a new entry is added to `items`, a +rerender occurs: + +```tsx +import { Component, State, h } from '@stencil/core'; + +// a user defined, complex type describing an 'Item' +type Item = { + id: number; + description: string, +} + +@Component({ + tag: 'item-list', +}) +export class ItemList { + // `timer` is not decorated with `@State()`, as + // we do not wish to trigger a rerender when its + // value changes + timer: number; + + // `items` will trigger a rerender if + // the value assigned to the variable changes + @State() items: Item[] = []; + + connectedCallback() { + // the assignment to `this.timer` will not + // trigger a re-render + this.timer = window.setInterval(() => { + const newTodo: Item = { + description: "Item", + id: this.items.length + 1 + }; + // the assignment to `this.items` will + // trigger a re-render. the assignment + // using '=' is important here, as we + // need that to make sure the rerender + // occurs + this.items = [...this.items, newTodo]; + }, 2000); + } + + disconnectedCallback() { + window.clearInterval(this.timer); + } + + render() { + return ( +
    +

    To-Do List

    +
      + {this.items.map((todo) =>
    • {todo.description} #{todo.id}
    • )} +
    +
    + ); + } +} +``` + +It's important to note that it's the reassignment of `this.items` that is causing the rerender in `connectedCallback()`: +```ts +this.items = [...this.items, newTodo]; +``` + +Mutating the existing reference to `this.items` like in the examples below will not cause a rerender, as Stencil will +not know that the contents of the array has changed: +```ts +// updating `items` either of these ways will not +// cause a rerender +this.items.push(newTodo); +this.items[this.items.length - 1] = newTodo; +``` + +Similar to the examples above, this code sample makes use of the +[connectedCallback() lifecycle method](./component-lifecycle.md#connectedcallback) to create a new `Item` and add +it to `items` every 2000 milliseconds (every two seconds). The example above also makes use of the +[disconnectedCallback() lifecycle method](./component-lifecycle.md#disconnectedcallback) to properly clean up the timer +that was created using `setInterval` in `connectedCallback()`. diff --git a/versioned_docs/version-v4.18/components/styling.md b/versioned_docs/version-v4.18/components/styling.md new file mode 100644 index 000000000..b8e4408be --- /dev/null +++ b/versioned_docs/version-v4.18/components/styling.md @@ -0,0 +1,338 @@ +--- +title: Styling Components +sidebar_label: Styling +description: Styling Components +slug: /styling +--- + +# Styling Components + +## Shadow DOM + +### What is the Shadow DOM? + +The [shadow DOM](https://developers.google.com/web/fundamentals/web-components/shadowdom) is an API built into the browser that allows for DOM encapsulation and style encapsulation. It is a core aspect of the Web Component standards. The shadow DOM shields a component’s styles, markup, and behavior from its surrounding environment. This means that we do not need to be concerned about scoping our CSS to our component, nor worry about a component’s internal DOM being interfered with by anything outside the component. + +When talking about the shadow DOM, we use the term "light DOM" to refer to the “regular” DOM. The light DOM encompasses any part of the DOM that does not use the shadow DOM. + +### Shadow DOM in Stencil + +The shadow DOM hides and separates the DOM of a component in order to prevent clashing styles or unwanted side effects. We can use the shadow DOM in our Stencil components to ensure our components won’t be affected by the applications in which they are used. + +To use the Shadow DOM in a Stencil component, you can set the `shadow` option to `true` in the component decorator. + +```tsx +@Component({ + tag: 'shadow-component', + styleUrl: 'shadow-component.css', + shadow: true, +}) +export class ShadowComponent {} +``` + +If you'd like to learn more about enabling and configuring the shadow DOM, see the [shadow field of the component api](./component.md#component-options). + +By default, components created with the [`stencil generate` command](../config/cli.md#stencil-generate) use the shadow DOM. + +### Styling with the Shadow DOM + +With the shadow DOM enabled, elements within the shadow root are scoped, and styles outside of the component do not apply. As a result, CSS selectors inside the component can be simplified, as they will only apply to elements within the component. We do not have to include any specific selectors to scope styles to the component. + +```css +:host { + color: black; +} + +div { + background: blue; +} +``` + +:::note +The `:host` pseudo-class selector is used to select the [`Host` element](./host-element.md) of the component +::: + +With the shadow DOM enabled, only these styles will be applied to the component. Even if a style in the light DOM uses a selector that matches an element in the component, those styles will not be applied. + +### Shadow DOM QuerySelector + +When using Shadow DOM and you want to query an element inside your web component, you must first use the [`@Element` decorator](./host-element.md#element-decorator) to gain access to the host element, and then you can use the `shadowRoot` property to perform the query. This is because all of your DOM inside your web component is in a shadowRoot that Shadow DOM creates. For example: + +```tsx +import { Component, Element } from '@stencil/core'; + +@Component({ + tag: 'shadow-component', + styleUrl: 'shadow-component.css', + shadow: true +}) +export class ShadowComponent { + + @Element() el: HTMLElement; + + componentDidLoad() { + const elementInShadowDom = this.el.shadowRoot.querySelector('.a-class-selector'); + + ... + } + +} +``` + +### Shadow DOM Browser Support + +The shadow DOM is currently natively supported in the following browsers: + +- Chrome +- Firefox +- Safari +- Edge (v79+) +- Opera + +In browsers which do not support the shadow DOM we fall back to scoped CSS. This gives you the style encapsulation that comes along with the shadow DOM but without loading in a huge shadow DOM polyfill. + +### Scoped CSS + +An alternative to using the shadow DOM is using scoped components. You can use scoped components by setting the `scoped` option to `true` in the component decorator. + +```tsx +@Component({ + tag: 'scoped-component', + styleUrl: 'scoped-component.css', + scoped: true, +}) +export class ScopedComponent {} +``` + +Scoped CSS is a proxy for style encapsulation. It works by appending a data attribute to your styles to make them unique and thereby scope them to your component. It does not, however, prevent styles from the light DOM from seeping into your component. + +## CSS Custom Properties + +CSS custom properties, also often referred to as CSS variables, are used to contain values that can then be used in multiple CSS declarations. For example, we can create a custom property called `--color-primary` and assign it a value of `blue`. + +```css +:host { + --color-primary: blue; +} +``` + +And then we can use that custom property to style different parts of our component + +```css +h1 { + color: var(--color-primary); +} +``` + +### Customizing Components with Custom Properties + +CSS custom properties can allow the consumers of a component to customize a component’s styles from the light DOM. Consider a `shadow-card` component that uses a custom property for the color of the card heading. + +```css +:host { + --heading-color: black; +} + +.heading { + color: var(--heading-color); +} +``` + +:::note +CSS custom properties must be declared on the `Host` element (`:host`) in order for them to be exposed to the consuming application. +::: + +The `shadow-card` heading will have a default color of `black`, but this can now be changed in the light DOM by selecting the `shadow-card` and changing the value of the `--heading-color` custom property. + +```css +shadow-card { + --heading-color: blue; +} +``` + +## CSS Parts + +CSS custom properties can be helpful for customizing components from the light DOM, but they are still a little limiting as they only allow a user to modify specific properties. For situations where users require a higher degree of flexibility, we recommend using the [CSS `::part()` pseudo-element](https://developer.mozilla.org/en-US/docs/Web/CSS/::part). You can define parts on elements of your component with the “part” attribute. + +```tsx +@Component({ + tag: 'shadow-card', + styleUrl: 'shadow-card.css', + shadow: true, +}) +export class ShadowCard { + @Prop() heading: string; + + render() { + return ( + +

    {this.heading}

    + +
    + ); + } +} +``` + +Then you can use the `::part()` pseudo-class on the host element to give any styles you want to the element with the corresponding part. + +```css +shadow-card::part(heading) { + text-transform: uppercase; +} +``` + +This allows for greater flexibility in styling as any styles can now be added to this element. + +### Exportparts + +If you have a Stencil component nested within another component, any `part` specified on elements of the child component will not be exposed through the parent component. In order to expose the `part`s of the child component, you need to use the `exportparts` attribute. Consider this `OuterComponent` which contains the `InnerComponent`. + +```tsx +@Component({ + tag: 'outer-component', + styleUrl: 'outer-component.css', + shadow: true, +}) +export class OuterComponent { + render() { + return ( + +

    Outer Component

    + +
    + ); + } +} + +@Component({ + tag: 'inner-component', + styleUrl: 'inner-component.css', + shadow: true, +}) +export class InnerComponent { + render() { + return ( + +

    Inner Component

    +
    + ); + } +} +``` + +By specifying "inner-text" as the value of the `exportparts` attribute, elements of the `InnerComponent` with a `part` of "inner-text" can now be styled in the light DOM. Even though the `InnerComponent` is not used directly, we can style its parts through the `OuterComponent`. + +```html + + + +``` + +## Style Modes + +Component Style Modes enable you to create versatile designs for your components by utilizing different styling configurations. This is achieved by assigning the styleUrls property of a component to a collection of style mode names, each linked to their respective CSS files. + +### Example: Styling a Button Component + +Consider a basic button component that supports both iOS and Material Design aesthetics: + +```tsx title="Using style modes to style a component" +@Component({ + tag: 'simple-button', + styleUrls: { + md: './simple-button.md.css', // styles for Material Design + ios: './simple-button.ios.css' // styles for iOS + }, +}) +export class SimpleButton { + // ... +} +``` + +In the example above, two different modes are declared. One mode is named `md` (for 'Material Design') and refers back to a Material Design-specific stylesheet. Likewise, the other is named `ios` (for iOS) and references a different stylesheet for iOS-like styling. Both stylesheets are relative paths to the file that declares the component. While we have chosen short names in the above example, there's no limitation to the keys used in the `styleUrls` object. + +To dictate the style mode (Material Design or iOS) in which the button should be rendered, you must initialize the desired mode before any component rendering occurs. This can be done as follows: + +```ts +import { setMode } from '@stencil/core'; +setMode(() => 'ios'); // Setting iOS as the default mode for all components +``` + +The `setMode` function processes all elements, enabling the assignment of modes individually based on specific element attributes. For instance, by assigning the `mode` attribute to a component: + +```html + +``` + +You can conditionally set the style mode based on the `mode` property: + +```ts +import { setMode } from '@stencil/core'; + +const defaultMode = 'md'; // Default to Material Design +setMode((el) => el.getAttribute('mode') || defaultMode); +``` + +The reason for deciding which mode to apply can be very arbitrary and based on your requirements, using an element property called `mode` is just one example. + +### Important Considerations + +- __Initialization:__ Style modes must be defined at the start of the component lifecycle and cannot be changed thereafter. If you like to change the components mode dynamically you will have to re-render it entirely. +- __Usage Requirement:__ A style mode must be set to ensure the component loads with styles. Without specifying a style mode, the component will not apply any styles. +- __Input Validation:__ Verify a style mode is supported by a component you are setting it for. Setting an un-supported style mode keeps the component unstyled. +- __Querying Style Mode:__ To check the current style mode and e.g. provide different functionality based on the mode, use the `getMode` function: + +```ts +import { getMode } from '@stencil/core'; + +const simpleButton = document.queryElement('simple-button') +console.log(getMode(simpleButton)); // Outputs the current style mode of component +``` + +This approach ensures your components are adaptable and can dynamically switch between different styles, enhancing the user experience across various platforms and design preferences. + +## Global styles + +While most styles are usually scoped to each component, sometimes it's useful to have styles that are available to all the components in your project. To create styles that are globally available, start by creating a global stylesheet. For example, you can create a folder in your `src` directory called `global` and create a file called `global.css` within that. Most commonly, this file is used to declare CSS custom properties on the root element via the `:root` pseudo-class. This is because styles provided via the `:root` pseudo-class can pass through the shadow boundary. For example, you can define a primary color that all your components can use. + +```css +:root { + --color-primary: blue; +} +``` + +In addition to CSS custom properties, other use cases for a global stylesheet include + +- Theming: defining CSS variables used across the app +- Load fonts with `@font-face` +- App wide font-family +- CSS resets + +To make the global styles available to all the components in your project, the `stencil.config.ts` file comes with an optional [`globalStyle` setting](../config/01-overview.md#globalstyle) that accepts the path to your global stylesheet. + +```tsx +export const config: Config = { + namespace: 'app', + globalStyle: 'src/global/global.css', + outputTarget: [ + { + type: 'www', + }, + ], +}; +``` + +The compiler will run the same minification, autoprefixing, and plugins over `global.css` and generate an output file for the [`www`](../output-targets/www.md) and [`dist`](../output-targets/dist.md) output targets. The generated file will always have the `.css` extension and be named as the specified `namespace`. + +In the example above, since the namespace is `app`, the generated global styles file will be located at: `./www/build/app.css`. + +This file must be manually imported in the `index.html` of your application. + +```html + +``` diff --git a/versioned_docs/version-v4.18/components/templating-and-jsx.md b/versioned_docs/version-v4.18/components/templating-and-jsx.md new file mode 100644 index 000000000..43847d481 --- /dev/null +++ b/versioned_docs/version-v4.18/components/templating-and-jsx.md @@ -0,0 +1,471 @@ +--- +title: Using JSX +sidebar_label: Using JSX +description: Using JSX +slug: /templating-jsx +--- + +# Using JSX + +Stencil components are rendered using JSX, a popular, declarative template syntax. Each component has a `render` function that returns a tree of components that are rendered to the DOM at runtime. + +## Basics + +The `render` function is used to output a tree of components that will be drawn to the screen. + +```tsx +class MyComponent { + render() { + return ( +
    +

    Hello World

    +

    This is JSX!

    +
    + ); + } +} +``` + +In this example we're returning the JSX representation of a `div`, with two child elements: an `h1` and a `p`. + +### Host Element + +If you want to modify the host element itself, such as adding a class or an attribute to the component itself, use the `` functional component. Check for more details [here](./host-element.md) + + +## Data Binding + +Components often need to render dynamic data. To do this in JSX, use `{ }` around a variable: + +```tsx +render() { + return ( +
    Hello {this.name}
    + ) +} +``` + +:::note +If you're familiar with ES6 template variables, JSX variables are very similar, just without the `$`: +::: + +```tsx +//ES6 +`Hello ${this.name}` + +//JSX +Hello {this.name} +``` + + +## Conditionals + +If we want to conditionally render different content, we can use JavaScript if/else statements: +Here, if `name` is not defined, we can just render a different element. + +```tsx +render() { + if (this.name) { + return (
    Hello {this.name}
    ) + } else { + return (
    Hello, World
    ) + } +} +``` + +Additionally, inline conditionals can be created using the JavaScript ternary operator: + +```tsx +render() { + return ( +
    + {this.name + ?

    Hello {this.name}

    + :

    Hello World

    + } +
    + ); +} +``` + +**Please note:** Stencil reuses DOM elements for better performance. Consider the following code: + +```tsx +{someCondition + ? + : +} +``` + +The above code behaves exactly the same as the following code: + +```tsx + +``` + +Thus, if `someCondition` changes, the internal state of `` won't be reset and its lifecycle methods such as `componentWillLoad()` won't fire. Instead, the conditional merely triggers an update to the very same component. + +If you want to destroy and recreate a component in a conditional, you can assign the `key` attribute. This tells Stencil that the components are actually different siblings: + +```tsx +{someCondition + ? + : +} +``` + +This way, if `someCondition` changes, you get a new `` component with fresh internal state that also runs the lifecycle methods `componentWillLoad()` and `componentDidLoad()`. + + +## Slots + +Components often need to render dynamic children in specific locations in their component tree, allowing a developer to supply child content when using our component, with our component placing that child component in the proper location. + +To do this, you can use the [Slot](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) tag inside of your `my-component`. + +```tsx +// my-component.tsx + +render() { + return ( +
    +

    A Component

    +
    +
    + ); +} + +``` + +Then, if a user passes child components when creating our component `my-component`, then `my-component` will place that +component inside of the second `
    ` above: + +```tsx +render(){ + return( + +

    Child Element

    +
    + ) +} +``` + +Slots can also have `name`s to allow for specifying slot output location: + +```tsx +// my-component.tsx + +render(){ + return [ + , +

    Here is my main content

    , + + ] +} +``` + +```tsx +render(){ + return( + +

    I'll be placed before the h1

    +

    I'll be placed after the h1

    +
    + ) +} +``` + +### Slots Outside Shadow DOM + +:::caution +Slots are native to the [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), but Stencil polyfills +the behavior to work for non-shadow components as well. However, you may encounter issues using slots outside the Shadow DOM especially with +component trees mixing shadow and non-shadow components, or when passing a slot through many levels of components. In many cases, this behavior can +be remedied by wrapping the `slot` in an additional element (like a `div` or `span`) so the Stencil runtime can correctly "anchor" the relocated +content in its new location. +::: + +There are known use cases that the Stencil runtime is not able to support: + +- Forwarding slotted content to another slot with a different name:
    + It is recommended that slot names stay consistent when slotting content through multiple levels of components. **Avoid** defining slot tags like + ``. + +## Dealing with Children + +The children of a node in JSX correspond at runtime to an array of nodes, +whether they are created by mapping across an array with +[`Array.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) +or simply declared as siblings directly in JSX. This means that at runtime the +children of the two top-level divs below (`.todo-one` and `.todo-two`) will be +represented the same way: + + +```tsx +render() { + return ( + <> +
    + {this.todos.map((todo) => ( + { todo.taskName } + )} +
    +
    + { todos[0].taskName } + { todos[1].taskName } +
    + + ) +} +``` + +If this array of children is dynamic, i.e., if any nodes may be added, +removed, or reordered, then it's a good idea to set a unique `key` attribute on +each element like so: + +```tsx +render() { + return ( +
    + {this.todos.map((todo) => ( +
    +
    {todo.taskName}
    +
    + ))} +
    + ) +} +``` + +When nodes in a children array are rearranged Stencil makes an effort to +preserve DOM nodes across renders but it isn't able to do so in all cases. +Setting a `key` attribute lets Stencil ensure it can match up new and old +children across renders and thereby avoid recreating DOM nodes unnecessarily. + +:::caution +Do not use an array index or some other non-unique value as a key. Try to +ensure that each child has a key which does not change and which is unique +among all its siblings. +::: + +### Automatic Key Insertion + +During compilation Stencil will automatically add key attributes to any JSX +nodes in your component's render method which are not nested within curly +braces. This allows Stencil’s runtime to accurately reconcile children when +their order changes or when a child is conditionally rendered. + +For instance, consider a render method looking something like this: + +```tsx + render() { + return ( +
    + { this.disabled &&
    no key!
    } +
    + +
    +
    + ); + } +``` + +While it might seem like adding a key attribute to the `#slot-wrapper` div +could help ensure that elements will be matched up correctly when the component +re-renders, this is actually superfluous because Stencil will automatically add +a key to that element when it compiles your component. + +:::note +The Stencil compiler can only safely perform automatic key insertion in certain +scenarios where there is no danger of the keys accidentally causing elements to +be considered different when they should be treated the same (or vice versa). + +In particular, the compiler will not automatically insert `key` attributes if a +component's `render` method has more than one `return` statement or if it +returns a [conditional +expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator). +Additionally, the compiler will not add key attributes to any JSX which is +found within curly braces (`{ }`). +::: + +## Handling User Input + +Stencil uses native [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events). + +Here's an example of handling a button click. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private handleClick = () => { + alert('Received the button click!'); + } + + render() { + return ( + + ); + } +} +``` + +Here's another example of listening to input `change`. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private inputChanged = (event: Event) => { + console.log('input changed: ', (event.target as HTMLInputElement).value); + } + + render() { + return ( + + ); + } +} +``` + + +## Complex Template Content + +So far we've seen examples of how to return only a single root element. We can also nest elements inside our root element + +In the case where a component has multiple "top level" elements, the `render` function can return an array. +Note the comma in between the `
    ` elements. + +```tsx +render() { + return ([ + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    , + + // second top level element, note the , above +
    + ... more html content ... +
    + ]); +} +``` + +Alternatively you can use the `Fragment` functional component, in which case you won't need to add commas: + +```tsx +import { Fragment } from '@stencil/core'; +... +render() { + return ( + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    + +
    + ... more html content ... +
    +
    ); +} +``` + +It is also possible to use `innerHTML` to inline content straight into an element. This can be helpful when, for example, loading an svg dynamically and then wanting to render that inside of a `div`. This works just like it does in normal HTML: + +```markup +
    +``` + +## Getting a reference to a DOM element + +In cases where you need to get a direct reference to an element, like you would normally do with `document.querySelector`, you might want to use a `ref` in JSX. Lets look at an example of using a `ref` in a form: + +```tsx +@Component({ + tag: 'app-home', +}) +export class AppHome { + + textInput!: HTMLInputElement; + + handleSubmit = (event: Event) => { + event.preventDefault(); + console.log(this.textInput.value); + } + + render() { + return ( +
    + + +
    + ); + } +} +``` + +In this example we are using `ref` to get a reference to our input `ref={(el) => this.textInput = el as HTMLInputElement}`. We can then use that ref to do things such as grab the value from the text input directly `this.textInput.value`. + + +## Avoid Shared JSX Nodes + +The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be shared within the same renderer. + +In the example below, the `sharedNode` variable is reused multiple times within the `render()` function. The renderer is able to optimize its DOM element lookups by caching the reference, however, this causes issues when nodes are reused. Instead, it's recommended to always generate unique nodes like the changed example below. + +```diff +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + render() { +- const sharedNode =
    Text
    ; + return ( +
    +- {sharedNode} +- {sharedNode} ++
    Text
    ++
    Text
    +
    + ); + } +} +``` + +Alternatively, creating a factory function to return a common JSX node could be used instead since the returned value would be a unique instance. For example: + +```tsx +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + getText() { + return
    Text
    ; + } + + render() { + return ( +
    + {this.getText()} + {this.getText()} +
    + ); + } +} +``` + +## Other Resources + +- [Understanding JSX for StencilJS Applications](https://www.joshmorony.com/understanding-jsx-for-stencil-js-applications/) diff --git a/versioned_docs/version-v4.18/config/01-overview.md b/versioned_docs/version-v4.18/config/01-overview.md new file mode 100644 index 000000000..c800d076e --- /dev/null +++ b/versioned_docs/version-v4.18/config/01-overview.md @@ -0,0 +1,505 @@ +--- +title: Config +sidebar_label: Overview +description: Config +slug: /config +--- + +# Stencil Config + +In most cases, the `stencil.config.ts` file does not require any customization since Stencil comes with great default values out-of-the-box. In general, it's preferred to keep the config as minimal as possible. In fact, you could even delete the `stencil.config.ts` file entirely and an app would compile just fine. But at the same time, the compiler can be configured at the lowest levels using this config. Below are the many *optional* config properties. + +Example `stencil.config.ts`: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'MyApp', + srcDir: 'src' +}; +``` + +## buildDist + +*default: true (prod), false (dev)* + +Sets whether or not Stencil will execute output targets and write output to +`dist/` when `stencil build` is called. Defaults to `false` when building for +development and `true` when building for production. If set to `true` then +Stencil will always build all output targets, regardless of whether the build +is in dev or prod mode or using watch mode. + +```tsx +buildDist: true +``` + +## buildEs5 + +Sets if the ES5 build should be generated or not. +It defaults to `false`. +Setting `buildEs5` to `true` will also create ES5 builds for both dev and prod modes. +Setting `buildEs5` to `prod` will only build ES5 in prod mode. + +```tsx +buildEs5: boolean | 'prod' +``` + +## bundles + +By default, Stencil will statically analyze the application and generate a component graph of how all the components are interconnected. From the component graph it is able to best decide how components should be grouped depending on their usage with one another within the app. By doing so it's able to bundle components together in order to reduce network requests. However, bundles can be manually generated using the `bundles` config. + +The `bundles` config is an array of objects that represent how components are grouped together in lazy-loaded bundles. This config is rarely needed as Stencil handles this automatically behind the scenes. + +```tsx +bundles: [ + { components: ['ion-button'] }, + { components: ['ion-card', 'ion-card-header'] } +] +``` + +## cacheDir + +*default: '.stencil'* + +The directory where sub-directories will be created for caching when [`enableCache`](#enablecache) is set `true` or if using +[Stencil's Screenshot Connector](../testing/stencil-testrunner/07-screenshot-connector.md). + +A Stencil config like the following: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + enableCache: true, + cacheDir: '.cache', + testing: { + screenshotConnector: 'connector.js' + } +} +``` + +Will result in the following file structure: + +```tree +stencil-project-root +└── .cache + ├── .build <-- Where build related file caching is written + | + └── screenshot-cache.json <-- Where screenshot caching is written +``` + +## devServer + +Please see the [Dev-Server docs](./dev-server.md). + +## enableCache + +*default: `true`* + +Stencil will cache build results in order to speed up rebuilds. To disable this feature, set `enableCache` to `false`. + +```tsx +enableCache: true +``` + +## extras + +Please see the [Extras docs](./extras.md). + +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + +## globalScript + +The global script config option takes a file path as a string. + +The global script runs once before your library/app loads, so you can do things like setting up a connection to an external service or configuring a library you are using. + +The code to be executed should be placed within a default function that is exported by the global script. Ensure all of the code in the global script is wrapped in the function that is exported: + +```javascript +export default function() { // or export default async function() + initServerConnection(); +} +``` + +:::note +The exported function can also be `async` but be aware that this can have implications on the performance of your application as all rendering operations will be deferred until after the global script finishes. +::: + +## globalStyle + +Stencil is traditionally used to compile many components into an app, and each component comes with its own compartmentalized styles. However, it's still common to have styles which should be "global" across all components and the website. A global CSS file is often useful to set [CSS Variables](../components/styling.md). + +Additionally, the `globalStyle` config can be used to precompile styles with Sass, PostCSS, etc. + +Below is an example folder structure containing a webapp's global css file, named `app.css`. + +```bash +src/ + components/ + global/ + app.css +``` + +The global style config takes a file path as a string. The output from this build will go to the `buildDir`. In this example it would be saved to `www/build/app.css`. + +```tsx +globalStyle: 'src/global/app.css' +``` + +Check out the [styling docs](../components/styling.md#global-styles) of how to use global styles in your app. + +## hashedFileNameLength + +*default: `8`* + +When the `hashFileNames` config is set to `true`, and it is a production build, the `hashedFileNameLength` config is used to determine how many characters the file name's hash should be. + +```tsx +hashedFileNameLength: 8 +``` + +## hashFileNames + +*default: `true`* + +During production builds, the content of each generated file is hashed to represent the content, and the hashed value is used as the filename. If the content isn't updated between builds, then it receives the same filename. When the content is updated, then the filename is different. By doing this, deployed apps can "forever-cache" the build directory and take full advantage of content delivery networks (CDNs) and heavily caching files for faster apps. + +```tsx +hashFileNames: true +``` + +## hydratedFlag + +When using the [lazy build](https://stenciljs.com/docs/distribution) Stencil +has support for automatically applying a class or attribute to a component and +all of its child components when they have finished hydrating. This can be used +to prevent a [flash of unstyled content +(FOUC)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content), a +typically-undesired 'flicker' of unstyled HTML that might otherwise occur +during component rendering while various components are asynchronously +downloaded and rendered. + +By default, Stencil will add the `hydrated` CSS class to elements to indicate +hydration. The `hydratedFlag` config field allows this behavior to be +customized, by changing the name of the applied CSS class, setting it to use an +attribute to indicate hydration, or changing which type of CSS properties and +values are assigned before and after hydrating. This config can also be used to +turn off this behavior by setting it to `null`. + +If a Stencil configuration does not supply a value for `hydratedFlag` then +Stencil will automatically generate the following default configuration: + +```ts +const defaultHydratedFlag: HydratedFlag = { + hydratedValue: 'inherit', + initialValue: 'hidden', + name: 'hydrated', + property: 'visibility', + selector: 'class', +}; +``` + +If `hydratedFlag` is explicitly set to `null`, Stencil will not set a default +configuration and the behavior of marking hydration with a class or attribute +will be disabled. + +```tsx +hydratedFlag: null | { + name?: string, + selector?: 'class' | 'attribute', + property?: string, + initialValue?: string, + hydratedValue?: string +} +``` + +The supported options are as follows: + +### name + +*default: 'hydrated'* + +The name which Stencil will use for the attribute or class that it sets on +elements to indicate that they are hydrated. + +```tsx +name: string +``` + +### selector + +*default: 'class'* + +The way that Stencil will indicate that a component has been hydrated. When +`'class'`, Stencil will set the `name` option on the element as a class, and +when `'attribute'`, Stencil will similarly set the `name` option as an +attribute. + +```tsx +selector: 'class' | 'attribute' +``` + +### property + +*default: 'visibility'* + +The CSS property used to show and hide components. This defaults to the CSS +`visibility` property. Other possible CSS properties might include `display` +with the `initialValue` setting as `none`, or `opacity` with the `initialValue` +as `0`. Defaults to `visibility`. + +```tsx +property: string +``` + +### initialValue + +*default: 'hidden'* + +This is the value which should be set for the property specified by `property` +on all components before hydration. + +```tsx +initialValue: string +``` + +### hydratedValue + +*default: 'inherit'* + +This is the value which should be set for the property specified by `property` +on all components once they've completed hydration. + +```tsx +hydratedValue: string +``` + +## invisiblePrehydration + +*default: `true`* + +When `true`, `invisiblePrehydration` will visually hide components before they are hydrated by adding an automatically injected style tag to the document's head. Setting `invisiblePrehydration` to `false` will not inject the style tag into the head, allowing you to style your web components pre-hydration. + +:::note +Setting `invisiblePrehydration` to `false` will cause everything to be visible when your page is loaded, causing a more prominent Flash of Unstyled Content (FOUC). However, you can style your web component's fallback content to your preference. +::: + +```tsx +invisiblePrehydration: true +``` + +## minifyCss + +_default: `true` in production_ + +When `true`, the browser CSS file will be minified. + +## minifyJs + +_default: `true` in production_ + +When `true`, the browser JS files will be minified. Stencil uses [Terser](https://terser.org/) under-the-hood for file minification. + +## namespace + +*default: `App`* + +The `namespace` config is a `string` representing a namespace for the app. For apps that are not meant to be a library of reusable components, the default of `App` is just fine. However, if the app is meant to be consumed as a third-party library, such as `Ionic`, a unique namespace is required. + +```tsx +namespace: "Ionic" +``` +## outputTargets + +Please see the [Output Target docs](../output-targets/01-overview.md). + +## plugins + +Please see the [Plugin docs](./plugins.md). + +## preamble + +*default: `undefined`* + +Used to help to persist a banner or add relevant information about the resulting build, the `preamble` configuration +field is a `string` that will be converted into a pinned comment and placed at the top of all emitted JavaScript files, +with the exception of any emitted polyfills. Escaped newlines may be placed in the provided value for this field and +will be honored by Stencil. + +Example: +```tsx +preamble: 'Built with Stencil\nCopyright (c) SomeCompanyInc.' +``` +Will generate the following comment: +```tsx +/*! + * Built with Stencil + * Copyright (c) SomeCompanyInc. + */ +``` + +## sourceMap + +*default: `true`* + +When omitted or set to `true`, sourcemaps will be generated for a project. +When set to `false`, sourcemaps will not be generated. + +```tsx +sourceMap: true | false +``` + +Sourcemaps create a translation between Stencil components that are written in TypeScript/JSX and the resulting +JavaScript that is output by Stencil. Enabling source maps in your project allows for an improved debugging experience +for Stencil components. For example, they allow external tools (such as an Integrated Development Environment) to add +breakpoints directly in the original source code, which allows you to 'step through' your code line-by-line, to inspect +the values held in variables, to observe logic flow, and more. + +Please note: Stencil will always attempt to minify a component's source code as much as possible during compilation. +When `sourceMap` is enabled, it is possible that a slightly different minified result will be produced by Stencil when +compared to the minified result produced when `sourceMap` is not enabled. + +Developers are responsible for determining whether or not they choose to serve sourcemaps in each environment their +components are served and implementing their decision accordingly. + +## srcDir + +*default: `src`* + +The `srcDir` config specifies the directory which should contain the source typescript files for each component. The standard for Stencil apps is to use `src`, which is the default. + +```tsx +srcDir: 'src' +``` + +## taskQueue + +*default: `async`* + +Sets the task queue used by stencil's runtime. The task queue schedules DOM read and writes +across the frames to efficiently render and reduce layout thrashing. By default, the +`async` is used. It's recommended to also try each setting to decide which works +best for your use-case. In all cases, if your app has many CPU intensive tasks causing the +main thread to periodically lock-up, it's always recommended to try +[Web Workers](../guides/workers.md) for those tasks. + +* `congestionAsync`: DOM reads and writes are scheduled in the next frame to prevent layout + thrashing. When the app is heavily tasked and the queue becomes congested it will then + split the work across multiple frames to prevent blocking the main thread. However, it can + also introduce unnecessary reflows in some cases, especially during startup. `congestionAsync` + is ideal for apps running animations while also simultaneously executing intensive tasks + which may lock-up the main thread. + +* `async`: DOM read and writes are scheduled in the next frame to prevent layout thrashing. + During intensive CPU tasks it will not reschedule rendering to happen in the next frame. + `async` is ideal for most apps, and if the app has many intensive tasks causing the main + thread to lock-up, it's recommended to try [Web Workers](../guides/workers.md) + rather than the congestion async queue. + +* `immediate`: Makes writeTask() and readTask() callbacks to be executed synchronously. Tasks + are not scheduled to run in the next frame, but do note there is at least one microtask. + The `immediate` setting is ideal for apps that do not provide long-running and smooth + animations. Like the async setting, if the app has intensive tasks causing the main thread + to lock-up, it's recommended to try [Web Workers](../guides/workers.md). + +```tsx +taskQueue: 'async' +``` + +## testing + +Please see the [testing config docs](../testing/stencil-testrunner/02-config.md). + +## transformAliasedImportPaths + +*default: `true`* + +This sets whether or not Stencil should transform [path aliases]( +https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) set +in a project's `tsconfig.json` from the assigned module aliases to resolved +relative paths. This will not transform external imports (like `@stencil/core`) or +relative imports (like `'../utils'`). + +This option applies globally and will affect all code processed by Stencil, +including `.d.ts` files and spec tests. + +An example of path transformation could look something like the following. + +First, a set of `paths` aliases in `tsconfig.json`: + +```json title="tsconfig.json" +{ + "compilerOptions": { + "paths": { + "@utils": [ + "../path/to/utils" + ] + } + } +} +``` + +Then with the following input: + +```ts title="src/my-module.ts" +import { utilFunc, UtilInterface } from '@utils' + +export function util(arg: UtilInterface) { + utilFunc(arg) +} +``` + +Stencil will produce the following output: + +```js title="dist/my-module.js" +import { utilFunc } from '../path/to/utils'; +export function util(arg) { + utilFunc(arg); +} +``` + +```ts title="dist/my-module.d.ts" +import { UtilInterface } from '../path/to/utils'; +export declare function util(arg: UtilInterface): void; +``` + +## validatePrimaryPackageOutputTarget + +*default: `false`* + +When `true`, validation for common `package.json` fields will occur based on setting an output target's `isPrimaryPackageOutputTarget` flag. +For more information on package validation, please see the [output target docs](../output-targets/01-overview.md#primary-package-output-target-validation). diff --git a/versioned_docs/version-v4.18/config/_category_.json b/versioned_docs/version-v4.18/config/_category_.json new file mode 100644 index 000000000..b9de453d1 --- /dev/null +++ b/versioned_docs/version-v4.18/config/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Config", + "position": 5 +} diff --git a/versioned_docs/version-v4.18/config/cli.md b/versioned_docs/version-v4.18/config/cli.md new file mode 100644 index 000000000..5ea10a3a8 --- /dev/null +++ b/versioned_docs/version-v4.18/config/cli.md @@ -0,0 +1,107 @@ +--- +title: Stencil CLI +sidebar_label: CLI +description: Stencil CLI +slug: /cli +--- + +# Command Line Interface (CLI) + +Stencil's command line interface (CLI) is how developers can build their projects, run tests, and more. +Stencil's CLI is included in the compiler, and can be invoked with the `stencil` command in a project where `@stencil/core` is installed. + +## `stencil build` + +Builds a Stencil project. The flags below are the available options for the `build` command. + +| Flag | Description | Alias | +|------|-------------|-------| +| `--ci` | Run a build using recommended settings for a Continuous Integration (CI) environment. Defaults the number of workers to 4, allows for extra time if taking screenshots via the tests and modifies the console logs. | | +| `--config` | Path to the `stencil.config.ts` file. This flag is not needed in most cases since Stencil will find the config. Additionally, a Stencil config is not required. | `-c` | +| `--debug` | Adds additional runtime code to help debug, and sets the log level for more verbose output. | | +| `--dev` | Runs a development build. | | +| `--docs` | Generate all docs based on the component types, properties, methods, events, JSDocs, CSS Custom Properties, etc. | | +| `--es5` | Creates an ES5 compatible build. By default ES5 builds are not created during development in order to improve build times. However, ES5 builds are always created during production builds. Use this flag to create ES5 builds during development. | | +| `--log` | Write logs for the `stencil build` into `stencil-build.log`. The log file is written in the same location as the config. | | +| `--prerender` | Prerender the application using the `www` output target after the build has completed. | | +| `--prod` | Runs a production build which will optimize each file, improve bundling, remove unused code, minify, etc. A production build is the default, this flag is only used to override the `--dev` flag. | | +| `--max-workers` | Max number of workers the compiler should use. Defaults to use the same number of CPUs the Operating System has available. | | +| `--next` | Opt-in to test the "next" Stencil compiler features. | | +| `--no-cache` | Disables using the cache. | | +| `--no-open` | By default the `--serve` command will open a browser window. Using the `--no-open` command will not automatically open a browser window. | | +| `--port` | Port for the [Integrated Dev Server](./dev-server.md). Defaults to `3333`. | `-p` | +| `--serve` | Starts the [Integrated Dev Server](./dev-server.md). | | +| `--stats` | Write stats about the project to `stencil-stats.json`. The stats file is written in the same location as the config. | | +| `--verbose` | Logs additional information about each step of the build. | | +| `--watch` | Watches files during development and triggers a rebuild when files are updated. | | + +## `stencil docs` + +Performs a one-time generation of documentation for your project. +For more information on documentation generation, please see the [Documentation Generation section](../documentation-generation/01-overview.md). + +## `stencil generate` + +Alias: `stencil g` + +Starts the interactive generator for a new Stencil component. +The generator will ask you for a name for your component, and whether any stylesheets or testing files should be generated. + +If you wish to skip the interactive generator, a component tag name may be provided on the command line: +```shell +stencil generate my-new-component +``` + +All components will be generated within the `src/components` folder. +Within `src/components`, a directory will be created with the same name as the component tag name you provided containing the generated files. +For example, if you specify `page-home` as the component tag name, the files will be generated in `src/components/page-home`: +```plain +src +└── components + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +It is also possible to specify one or more sub-folders to generate the component in. +For example, if you specify `pages/page-home` as the component tag name, the files will be generated in `src/components/pages/page-home`: +```shell +stencil generate pages/page-home +``` +The command above will result in the following directory structure: +```plain +src +└── components + └── pages + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +## `stencil help` + +Aliases: `stencil --help`, `stencil -h` + +Prints various tasks that can be run and their associated flags to the terminal. + +## `stencil test` + +Tests a Stencil project. The flags below are the available options for the `test` command. + +| Flag | Description | +|------|-------------| +| `--spec` | Tests `.spec.ts` files using [Jest](https://jestjs.io/). | +| `--e2e` | Tests `.e2e.ts` files using [Puppeteer](https://developers.google.com/web/tools/puppeteer) and [Jest](https://jestjs.io/). | +| `--no-build` | Skips the build process before running end-to-end tests. When using this flag, it is assumed that your Stencil project has been built prior to running `stencil test`. Unit tests do not require this flag. | +| `--devtools` | Opens the dev tools panel in Chrome for end-to-end tests. Setting this flag will disable `--headless` | +| `--headless` | Sets the headless mode to use in Chrome for end-to-end tests. `--headless` and `--headless=true` will enable the "old" headless mode in Chrome, that was used by default prior to Chrome v112. `--headless=new` will enable the new headless mode introduced in Chrome v112. See [this article](https://developer.chrome.com/articles/new-headless/) for more information on Chrome's new headless mode. | + +## `stencil version` + +Aliases: `stencil -v`, `stencil --version` + +Prints the version of Stencil to the terminal. diff --git a/versioned_docs/version-v4.18/config/dev-server.md b/versioned_docs/version-v4.18/config/dev-server.md new file mode 100644 index 000000000..f83c55a05 --- /dev/null +++ b/versioned_docs/version-v4.18/config/dev-server.md @@ -0,0 +1,152 @@ +--- +title: Integrated Dev Server Config +sidebar_label: Dev Server +description: Integrated Dev Server Config +slug: /dev-server +--- + +# Integrated Dev Server + +Stencil comes with an integrated dev server in order to simplify development. By integrating the build process and the dev server, Stencil is able to drastically improve the development experience without requiring complicated build scripts and configuration. As app builds and re-builds take place, the compiler is able to communicate with the dev server, and vice versa. + +## Hot Module Replacement + +The compiler already provides a watch mode, but coupled with the dev server it's able to go one step farther by reloading only what has changed within the browser. Hot Module Replacement allows the app to keep its state within the browser, while switching out individual components with their updated logic after file saves. + +## Style Replacement + +Web components can come with their own css, can use shadow dom, and can have individual style tags. Traditionally, live-reload external css links usually does the trick, however, updating components with inline styles within shadow roots has been a challenge. With the integrated dev server, Stencil is able to dynamically update styles for all components, whether they're using shadow dom or not, without requiring a page refresh. + +## Development Errors + +When errors happen during development, such as printing an error for invalid syntax, Stencil will not only log the error and the source of the error in the console, but also overlay the app with the error so it's easier to read. + +## Open In Editor + +When a development error is shown and overlays the project within the browser, line numbers pointing to the source text are clickable, +which will open the source file directly in your IDE. + +## Dev Server Config + +### `address` + +**Optional** + +**Type: `string`** + +**Default: `0.0.0.0`** + +IP address used by the dev server. The default is `0.0.0.0`, which points to all IPv4 addresses on the local machine, such as `localhost`. + +### `basePath` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +Base path to be used by the server. Defaults to the root pathname. + +### `https` + +**Optional** + +**Type: `{ key: string; cert: string; } | false`** + +**Default: `false`** + +By default the dev server runs over the http protocol. Instead you can run it over https by providing your own SSL certificate and key (see example below). + +#### Example + +```tsx +import { readFileSync } from 'fs'; +import { Config } from '@stencil/core'; + +export const config: Config = { + devServer: { + reloadStrategy: 'pageReload', + port: 4444, + https: { + cert: readFileSync('cert.pem', 'utf8'), + key: readFileSync('key.pem', 'utf8'), + }, + }, +}; +``` + +### `initialLoadUrl` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +The URL the dev server should first open to. + +### `logRequests` + +**Optional** + +**Type: `boolean`** + +**Default: `false`** + +Every request to the server will be logged within the terminal. + +### `openBrowser` + +**Optional** + +**Type: `boolean`** + +**Default: `true`** + +By default, when dev server is started the local dev URL is opened in your default browser. However, to prevent this URL to be opened change this value to `false`. + +### `pingRoute` + +**Optional** + +**Type: `string | null`** + +**Default: `/ping`** + +Route to be registered on the dev server that will respond with a 200 OK response once the Stencil build has completed. The Stencil dev server will "spin up" +before the build process has completed, which can cause issues with processes that rely on the compiled and served output (like E2E testing). This route provides +a way for these processes to know when the build has finished and is ready to be accessed. + +If set to `null`, no route will be registered. + +### `port` + +**Optional** + +**Type: `number`** + +**Default: `3333`** + +Sets the server's port. + +### `reloadStrategy` + +**Optional** + +**Type: `'hmr' | 'pageReload' | null`** + +**Default: `hmr`** + +When files are watched and updated, by default the dev server will use `hmr` (Hot Module Replacement) to update the page without a full page refresh. +To have the page do a full refresh use `pageReload`. To disable any reloading, use `null`. + +### `root` + +**Optional** + +**Type: `string`** + +**Default: `www` output directory if exists, project root otherwise** + +The directory to serve files from. diff --git a/versioned_docs/version-v4.18/config/extras.md b/versioned_docs/version-v4.18/config/extras.md new file mode 100644 index 000000000..e73e05eae --- /dev/null +++ b/versioned_docs/version-v4.18/config/extras.md @@ -0,0 +1,137 @@ +--- +title: Extras Config +sidebar_label: Extras +description: Extras Config +slug: /config-extras +--- + +# Extras + +The `extras` config contains options to enable new/experimental features in +Stencil, add & remove runtime for DOM features that require manipulations to +polyfills, etc. For example, not all DOM APIs are fully polyfilled when using +the Slot polyfill. Most of these are opt-in, since not all users require the +additional runtime. + +### appendChildSlotFix + +By default, the slot polyfill does not update `appendChild()` so that it appends new child nodes into the correct child slot like how shadow dom works. This is an opt-in polyfill for those who need it. + +### cloneNodeFix + +By default, the runtime does not polyfill `cloneNode()` when cloning a component that uses the slot polyfill. This is an opt-in polyfill for those who need it. + +### enableImportInjection + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +Enabling this flag will allow downstream projects that consume a Stencil library and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalImportInjection + +:::caution +This flag has been deprecated in favor of [`enableImportInjection`](#enableimportinjection), which provides the same +functionality. `experimentalImportInjection` will be removed in a future major version of Stencil. +::: + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +This is an experimental flag that, when set to `true`, will allow downstream projects that consume a Stencil library +and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalScopedSlotChanges + +This option updates runtime behavior for Stencil's support of slots in **scoped** components to match more closely with +the native Shadow DOM behaviors. + +When set to `true`, the following behaviors will be applied: + +- Stencil will hide projected nodes that do not have a destination `slot` ([#2778](https://github.com/ionic-team/stencil/issues/2877)) (since v4.10.0) +- The `textContent` getter will return the text content of all nodes located in a slot (since v4.10.0) +- The `textContent` setter will overwrite all nodes located in a slot (since v4.10.0) + +Defaults to `false`. + +:::note +These behaviors only apply to components using scoped encapsulation! +::: + +### experimentalSlotFixes + +This option enables all current and future slot-related fixes. When enabled it +will enable the following options, overriding their values if they are +specified separately: + +- [`slotChildNodesFix`](#slotchildnodesfix) +- [`scopedSlotTextContentFix`](#scopedslottextcontentfix). +- [`appendChildSlotFix`](#appendchildslotfix) +- [`cloneNodeFix`](#clonenodefix) + +Slot-related fixes to the runtime will be added over the course of Stencil v4, +with the intent of making these the default behavior in Stencil v5. When set to +`true` fixes for the following issues will be applied: + +- Elements rendered outside of slot when shadow not enabled [(#2641)](https://github.com/ionic-team/stencil/issues/2641) (since v4.2.0) +- A slot gets the attribute hidden when it shouldn't [(#4523)](https://github.com/ionic-team/stencil/issues/4523) (since v4.7.0) +- Nested slots mis-ordered when not using Shadow DOM [(#2997)](https://github.com/ionic-team/stencil/issues/2997) (since v4.7.0) +- Inconsistent behavior: slot-fb breaks styling of default slot content in component with 'shadow: false' [(#2937)](https://github.com/ionic-team/stencil/issues/2937) (since v4.7.2) +- Slot content went missing within dynamic component [(#4284)](https://github.com/ionic-team/stencil/issues/4284) (since v4.8.2) +- Slot element loses its parent reference and disappears when its parent is rendered conditionally [(#3913)](https://github.com/ionic-team/stencil/issues/3913) (since v4.8.2) +- Failed to execute 'removeChild' on 'Node' [(#3278)](https://github.com/ionic-team/stencil/issues/3278) (since v4.9.0) +- React fails to manage children in Stencil slot [(#2259)](https://github.com/ionic-team/stencil/issues/2259) (since v4.9.0) +- Slot name is not updated when it is bind to a prop [(#2982)](https://github.com/ionic-team/stencil/issues/2982) (since 4.12.1) +- Conditionally rendered slots not working [(#5335)](https://github.com/ionic-team/stencil/issues/5335) (since 4.13.0) + +:::note +New fixes enabled by this experimental flag are not subject to Stencil's +[semantic versioning policy](../reference/versioning.md). +::: + +### lifecycleDOMEvents + +Dispatches component lifecycle events. By default these events are not dispatched, but by enabling this to `true` these events can be listened for on `window`. Mainly used for testing. + +| Event Name | Description | +| ----------------------------- | ------------------------------------------------------ | +| `stencil_componentWillLoad` | Dispatched for each component's `componentWillLoad`. | +| `stencil_componentWillUpdate` | Dispatched for each component's `componentWillUpdate`. | +| `stencil_componentWillRender` | Dispatched for each component's `componentWillRender`. | +| `stencil_componentDidLoad` | Dispatched for each component's `componentDidLoad`. | +| `stencil_componentDidUpdate` | Dispatched for each component's `componentDidUpdate`. | +| `stencil_componentDidRender` | Dispatched for each component's `componentDidRender`. | + +### scopedSlotTextContentFix + +An experimental flag that when set to `true`, aligns the behavior of invoking the `textContent` getter/setter on a scoped component to act more like a component that uses the shadow DOM. Specifically, invoking `textContent` on a component will adhere to the return values described in [MDN's article on textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#description). Defaults to `false`. + +### scriptDataOpts + +It is possible to assign data to the actual ` + + + + + +``` + +Alternatively, if you wanted to take advantage of ES Modules, you could include the components using an import statement. + +```markup + + + + + + + + +``` + +## Passing object props from a non-JSX element + +### Setting the prop manually + +```tsx +import { Prop } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: object; + @Prop() myArray: Array; +} +``` + +```markup + + +``` + +### Watching props changes + +```tsx +import { Prop, State, Watch } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: string; + @Prop() myArray: string; + @State() myInnerObject: object; + @State() myInnerArray: Array; + + componentWillLoad() { + this.parseMyObjectProp(this.myObject); + this.parseMyArrayProp(this.myArray); + } + + @Watch('myObject') + parseMyObjectProp(newValue: string) { + if (newValue) this.myInnerObject = JSON.parse(newValue); + } + + @Watch('myArray') + parseMyArrayProp(newValue: string) { + if (newValue) this.myInnerArray = JSON.parse(newValue); + } +} +``` + +```tsx + +``` diff --git a/versioned_docs/version-v4.18/framework-integration/react.md b/versioned_docs/version-v4.18/framework-integration/react.md new file mode 100644 index 000000000..973272942 --- /dev/null +++ b/versioned_docs/version-v4.18/framework-integration/react.md @@ -0,0 +1,505 @@ +--- +title: React Integration with Stencil +sidebar_label: React +description: Learn how to wrap your components so that people can use them natively in React +slug: /react +--- + +# React Integration + +**Supports: React v16.7+ • TypeScript 3.7+ • Stencil v2.9.0+** + +Stencil can generate React component wrappers for your web components. This allows your Stencil components to be used within +a React application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Custom events will be handled correctly and correctly propagate through the React render tree +- Properties and attributes that are not a string or number will be correctly bound to the component + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component +wrappers. Your project workspace should contain your Stencil component library and the library for the generated React component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── stencil-library/ + │ ├── stencil.config.js + │ └── src/components/ + └── react-library/ + └── src/ + ├── components/ + └── index.ts +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +From the `packages/` directory, run the following commands to create a Stencil component library: + +```bash npm2yarn +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a React Component Library + +:::note +If you already have a React component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a React library package to write to. + +Run the following commands from the root directory of your monorepo to create a React component library: + +```bash npm2yarn +# Create a project +lerna create react-library # fill out the prompts accordingly +cd packages/react-library + +# Install core dependencies +npm install react react-dom typescript @types/react --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `react-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2015"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2015", + "skipLibCheck": true, + "jsx": "react", + "allowSyntheticDefaultImports": true, + "declarationDir": "./dist/types" + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `react-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/react-library.js", ++ "main": "dist/index.js", ++ "module": "dist/index.js", ++ "types": "dist/types/index.d.ts", + "scripts": { +- "test": "node ./__tests__/react-library.test.js" ++ "test": "node ./__tests__/react-library.test.js", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, + "files": [ +- "lib" ++ "dist" + ], ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the React Output Target + +Install the `@stencil/react-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency +npm install @stencil/react-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `reactOutputTarget` configuration to the `outputTargets` array: + +```ts +import { reactOutputTarget } from '@stencil/react-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // React target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + reactOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../react-library/lib/components/stencil-generated/index.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all of the React component wrappers. You will replace the +file path to match your project's structure and respective names. You can generate any file name instead of `index.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +See the [API section below](#api) for details on each of the output target's options. + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers +npm run build +``` + +If the build is successful, you’ll see the new generated file in your React component library at the location specified by the `proxiesFile` argument. + +### Add the Components to your React Component Library's Entry File + +In order to make the generated files available within your React component library and its consumers, you’ll need to export everything from within your entry file. First, rename `react-library.js` to `index.ts`. Then, modify the contents to match the following: + +```tsx +export * from './components/stencil-generated'; +``` + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you'll need to expose a method for registering the underlying Stencil +generated custom elements for the React proxy components to leverage. The easiest way to do this is to modify the React library's entry file +to re-export the Stencil loader's `defineCustomElements()` method. In your React library's entry file (`packages/react-library/lib/index.ts`), +add the following: + +```diff +export * from "./components/stencil-generated"; ++ export { defineCustomElements } from "stencil-library/loader"; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your React component library, you will need to link the Stencil package to the React package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your React component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the React component library. + +:::tip +As an alternative to `npm link` , you can also run `npm install` with a relative path to your Stencil component library. This strategy, however, will +modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer React App + +:::note +If you already have a React app, skip this section. +::: + +From the `packages/` directory, run the following commands to create a starter React app: + + + + +```bash +# Create the React app +npm create vite@latest my-app -- --template react-ts +# of if using yarn +yarn create vite my-app --template react-ts + +cd ./my-app + +# install dependencies +npm install +# or if using yarn +yarn install +``` + +You'll also need to link your React component library as a dependency. This step makes it so your React app will be able to correctly resolve imports from your React library. This +is easily done by modifying your React app's `package.json` to include the following: + +```json +"dependencies": { + "react-library": "*" +} +``` + +### Consuming the React Wrapper Components + +This section covers how developers consuming your React component wrappers will use your package and component wrappers. + +Before you can consume your React proxy components, you'll need to build your React component library. From `packages/react-library` run: + +```bash npm2yarn +npm run build +``` + +To make use of your React component library in your React application, import your components from your React component library in the file where you want to use them. + +```tsx +// App.tsx +import './App.css'; +import { MyComponent, defineCustomElements } from 'react-library'; + +defineCustomElements(); + +function App() { + return ( +
    + +
    + ); +} + +export default App; +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + reactOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate React wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with React Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements](../output-targets/custom-elements.md) output and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your React project. + +## FAQ's + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + reactOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the React output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the React application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the React component library. + +### What is the best format to write event names? + +Event names shouldn’t include special characters when initially written in Stencil. Try to lean on using camelCased event names for interoperability between frameworks. diff --git a/versioned_docs/version-v4.18/framework-integration/vue.md b/versioned_docs/version-v4.18/framework-integration/vue.md new file mode 100644 index 000000000..143a858a8 --- /dev/null +++ b/versioned_docs/version-v4.18/framework-integration/vue.md @@ -0,0 +1,673 @@ +--- +title: VueJS Integration with Stencil +sidebar_label: Vue +description: Learn how to wrap your components so that people can use them natively in Vue +slug: /vue +--- + +# Vue Integration + +**Supports: Vue 3 • TypeScript 4.0+ • Stencil v2.9.0+** + +Stencil can generate Vue component wrappers for your web components. This allows your Stencil components to be used within a Vue 3 application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Type checking with your components. +- Integration with the router link and Vue router. +- Optionally, form control web components can be used with `v-model`. + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component wrappers. Your project workspace should contain your Stencil component library and the library for the generate Vue component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── vue-library/ + │ └── lib/ + │ ├── plugin.ts + │ └── index.ts + └── stencil-library/ + ├── stencil.config.js + └── src/components +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +```bash npm2yarn +cd packages/ +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a Vue Component Library + +:::note +If you already have a Vue component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a Vue library package to write to. + +Using Lerna and Vue's CLI, generate a workspace and a library for your Vue component wrappers: + +```bash npm2yarn +# From your top-most-directory/ +lerna create vue-library +# Follow the prompts and confirm +cd packages/vue-library +# Install Vue dependency +npm install vue@3 --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `vue-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2020"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2017", + "skipLibCheck": true + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `vue-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/vue-library.js", ++ "main": "dist/index.js", ++ "types": "dist/index.d.ts", + "files": [ +- 'lib' ++ 'dist' + ], + "scripts": { +- "test": "echo \"Error: run tests from root\" && exit 1" ++ "test": "echo \"Error: run tests from root\" && exit 1", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the Vue Output Target + +Install the `@stencil/vue-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency (from `packages/stencil-library`) +npm install @stencil/vue-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `vueOutputTarget` configuration to the `outputTargets` array: + +```ts +import { vueOutputTarget } from '@stencil/vue-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // Vue target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + vueOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../vue-library/lib/components.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all the Vue component wrappers. You will replace the file path to match +your project's structure and respective names. You can generate any file name instead of `components.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers (from `packages/stencil-library`) +npm run build +``` + +If the build is successful, you will now have contents in the file specified in `proxiesFile`. + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you will need to create a new file for the Vue plugin: + +```ts +// packages/vue-library/lib/plugin.ts + +import { Plugin } from 'vue'; +import { applyPolyfills, defineCustomElements } from 'stencil-library/loader'; + +export const ComponentLibrary: Plugin = { + async install() { + applyPolyfills().then(() => { + defineCustomElements(); + }); + }, +}; +``` + +You can now finally export the generated component wrappers and the Vue plugin for your component library to make them available to implementers. Export +the `plugin.ts` file created in the previous step, as well as the file `proxiesFile` generated by the Vue Output Target: + +```ts +// packages/vue-library/lib/index.ts +export * from './components'; +export * from './plugin'; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your Vue component library, you will need to link the Stencil package to the Vue package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your Vue component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the Vue component library. + +:::note +As an alternative to `npm link`, you can also run `npm install` with a relative path to your Stencil component library. This strategy, +however, will modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer Vue App + +From the `packages/` directory, run the following command to generate a Vue app: + +```bash npm2yarn +npm init vue@3 my-app +``` + +Follow the prompts and choose the options best for your project. + +You'll also need to link your Vue component library as a dependency. This step makes it so your Vue app will be able to correctly +resolve imports from your Vue library. This is easily done by modifying your Vue app's `package.json` to include the following: + +```json +"dependencies": { + "vue-library": "*" +} +``` + +For more information, see the Lerna documentation on [package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management). + +Lastly, you'll want to update the generated `vite.config.ts`: + +```diff +export default defineConfig({ +- plugins: [vue(), vueJsx()], ++ plugins: [ ++ vue({ ++ template: { ++ compilerOptions: { ++ // treat all tags with a dash as custom elements ++ isCustomElement: (tag) => tag.includes('-'), ++ }, ++ }, ++ }), ++ vueJsx(), ++ ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } +}) +``` + +This will prevent Vue from logging a warning about failing to resolve components (e.g. "Failed to resolve component: my-component"). + +### Consuming the Vue Wrapper Components + +This section covers how developers consuming your Vue component wrappers will use your package and component wrappers. + +Before you can use your Vue proxy components, you'll need to build your Vue component library. From `packages/vue-library` simply run: + +```bash npm2yarn +npm run build +``` + +In your `main.js` file, import your component library plugin and use it: + +```js +// src/main.js +import { ComponentLibrary } from 'vue-library'; + +createApp(App).use(ComponentLibrary).mount('#app'); +``` + +In your page or component, you can now import and use your component wrappers: + +```html + +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### componentModels + +**Optional** + +**Default: `[]`** + +**Type: `ComponentModelConfig[]`** + +This option is used to define which components should be integrated with `v-model`. It allows you to set what the target prop is (i.e. `value`), +which event will cause the target prop to change, and more. + +```tsx +const componentModels: ComponentModelConfig[] = [ + { + elements: ['my-input', 'my-textarea'], + event: 'v-on-change', + externalEvent: 'on-change', + targetAttr: 'value', + }, +]; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + componentModels: componentModels, + }), + ], +}; +``` + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate Vue wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with Vue's Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements Bundle](../output-targets/custom-elements.md) and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your Vue project. + +## FAQ + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the Vue output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the Vue application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the Vue component library. + +### Vue warns "Failed to resolve component: my-component" + +#### Lazy loaded bundle + +If you are using Vue CLI, update your `vue.config.js` to match your custom element selector as a custom element: + +```js +const { defineConfig } = require('@vue/cli-service'); +module.exports = defineConfig({ + transpileDependencies: true, + chainWebpack: (config) => { + config.module + .rule('vue') + .use('vue-loader') + .tap((options) => { + options.compilerOptions = { + ...options.compilerOptions, + // The stencil-library components start with "my-" + isCustomElement: (tag) => tag.startsWith('my-'), + }; + return options; + }); + }, +}); +``` + +#### Custom elements bundle + +If you see this warning, then it is likely you did not import your component from your Vue library: `vue-library`. By default, all Vue components are locally registered, meaning you need to import them each time you want to use them. + +Without importing the component, you will only get the underlying Web Component, and Vue-specific features such as `v-model` will not work. + +To resolve this issue, you need to import the component from `vue-library` (your package name) and provide it to your Vue component: + +```html + + + +``` + +### Vue warns: "slot attributes are deprecated vue/no-deprecated-slot-attribute" + +The slots that are used in Stencil are [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots) slots, which are different than the slots used in Vue 2. Unfortunately, the APIs for both are very similar, and your linter is likely getting the two confused. + +You will need to update your lint rules in `.eslintrc.js` to ignore this warning: + +```js +module.exports = { + rules: { + 'vue/no-deprecated-slot-attribute': 'off', + }, +}; +``` + +If you are using VSCode and have the Vetur plugin installed, you are likely getting this warning because of Vetur, not ESLint. By default, Vetur loads the default Vue 3 linting rules and ignores any custom ESLint rules. + +To resolve this issue, you will need to turn off Vetur's template validation with `vetur.validation.template: false`. See the [Vetur Linting Guide](https://vuejs.github.io/vetur/guide/linting-error.html#linting) for more information. + +### Method on component is not a function + +In order to access a method on a Stencil component in Vue, you will need to access the underlying Web Component instance first: + +```ts +// ✅ This is correct +myComponentRef.value.$el.someMethod(); + +// ❌ This is incorrect and will result in an error. +myComponentRef.value.someMethod(); +``` + +### Output commonjs bundle for Node environments + +First, install `rollup` and `rimraf` as dev dependencies: + +```bash npm2yarn +npm i -D rollup rimraf +``` + +Next, create a `rollup.config.js` in `/packages/vue-library/`: + +```js +const external = ['vue', 'vue-router']; + +export default { + input: 'dist-transpiled/index.js', + output: [ + { + dir: 'dist/', + entryFileNames: '[name].esm.js', + chunkFileNames: '[name]-[hash].esm.js', + format: 'es', + sourcemap: true, + }, + { + dir: 'dist/', + format: 'commonjs', + preferConst: true, + sourcemap: true, + }, + ], + external: (id) => external.includes(id) || id.startsWith('stencil-library'), +}; +``` + +:::info +Update the `external` list for any external dependencies. Update the `stencil-library` to match your Stencil library's package name. +::: + +Next, update your `package.json` to include the scripts for rollup: + +```json +{ + "scripts": { + "build": "npm run clean && npm run tsc && npm run bundle", + "bundle": "rollup --config rollup.config.js", + "clean": "rimraf dist dist-transpiled" + } +} +``` diff --git a/versioned_docs/version-v4.18/guides/_category_.json b/versioned_docs/version-v4.18/guides/_category_.json new file mode 100644 index 000000000..afdb49ff4 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Guides", + "position": 8 +} diff --git a/versioned_docs/version-v4.18/guides/assets.md b/versioned_docs/version-v4.18/guides/assets.md new file mode 100644 index 000000000..f6dda9fce --- /dev/null +++ b/versioned_docs/version-v4.18/guides/assets.md @@ -0,0 +1,284 @@ +--- +title: Assets +sidebar_label: Assets +description: Learn how to reference assets in your components +slug: /assets +--- + +# Assets + +Stencil components may need one or more static files as a part of their design. +These types of files are referred to as 'assets', and include images, fonts, etc. + +In this guide, we describe different strategies for resolving assets on the filesystem. + +:::note +CSS files are handled differently than assets; for more on using CSS, please see the [styling documentation](../components/styling.md). +::: + +## Asset Base Path + +The **asset base path** is the directory that Stencil will use to resolve assets. +When a component uses an asset, the asset's location is resolved relative to the asset base path. + +The asset base path is automatically set for the following output targets: +- [dist](../output-targets/dist.md) +- [hydrate](./hydrate-app.md) +- [www](../output-targets/www.md) + +For all other output targets, assets must be [moved](#manually-moving-assets) and the asset base path must be [manually set](#setassetpath). + +For each instance of the Stencil runtime that is loaded, there is a single asset base path. +Oftentimes, this means there is only one asset base path per application using Stencil. + +## Resolution Overview + +The process of resolving an asset involves asking Stencil to build a path to the asset on the filesystem. + +When an asset's path is built, the resolution is always done in a project's compiled output, not the directory containing the original source code. + +The example below uses the output of the [`www` output target](../output-targets/www.md) to demonstrate how assets are resolved. +Although the example uses the output of `www` builds, the general principle of how an asset is found holds for all output targets. + +When using the `www` output target, a `build/` directory is automatically created and set as the asset base path. +An example `build/` directory and the assets it contains can be found below. + +``` +www/ +├── build/ +│ ├── assets/ +│ │ ├── logo.png +│ │ └── scenery/ +│ │ ├── beach.png +│ │ └── sunset.png +│ └── other-assets/ +│ └── font.tiff +└── ... +``` + +To resolve the path to an asset, Stencil's [`getAssetPath()` API](#getassetpath) may be used. +When using `getAssetPath`, the assets in the directory structure above are resolved relative to `build/`. + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments. +The return value is a path that Stencil has built to retrieve the asset on the filesystem. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": + +// '/build/assets/logo.png' +getAssetPath('assets/logo.png'); +// '/build/assets/scenery/beach.png' +getAssetPath('assets/scenery/beach.png'); +// '/build/other-assets/font.tiff' +getAssetPath('other-assets/font.tiff'); +``` + +## Making Assets Available + +In order to be able to find assets at runtime, they need to be found on the filesystem from the output of a Stencil build. +In other words, we need to ensure they exist in the distribution directory. +This section describes how to make assets available under the asset base path. + +### assetsDirs + +The `@Component` decorator can be [configured with the `assetsDirs` option](../components/component.md#component-options). +`assetsDirs` takes an array of strings, where each entry is a relative path from the component to a directory containing the assets the component requires. + +When using the `dist` or `www` output targets, setting `assetsDirs` instructs Stencil to copy that folder into the distribution folder. +When using other output targets, Stencil will not copy assets into the distribution folder. + +Below is an example project's directory structure containing an example component and an assets directory. + +``` +src/ +└── components/ + ├── assets/ + │ ├── beach.jpg + │ └── sunset.jpg + └── my-component.tsx +``` + +Below, the `my-component` component will correctly load the assets based on it's `image` prop. + +```tsx +// file: my-component.tsx +// 1. getAssetPath is imported from '@stencil/core' +import { Component, Prop, getAssetPath, h } from '@stencil/core'; + +@Component({ + tag: 'my-component', + // 2. assetsDirs lists the 'assets' directory as a relative + // (sibling) directory + assetsDirs: ['assets'] +}) +export class MyComponent { + + @Prop() image = "sunset.jpg"; + + render() { + // 3. the asset path is retrieved relative to the asset + // base path to use in the tag + const imageSrc = getAssetPath(`./assets/${this.image}`); + return + } +} +``` + +In the example above, the following allows `my-component` to display the provided asset: +1. [`getAssetPath()`](#getassetpath) is imported from `@stencil/core` +2. The `my-component`'s component decorator has the `assetsDirs` property, and lists the sibling directory, `assets`. This will copy `assets` over to the distribution directory. +3. `getAssetPath` is used to retrieve the path to the image to be used in the `` tag + +### Manually Moving Assets + +For the [dist-custom-elements](../output-targets/custom-elements.md) output target, options like `assetsDirs` do not copy assets to the distribution directory. + +It's recommended that a bundler (such as rollup) or a Stencil `copy` task is used to ensure the static assets are copied to the distribution directory. + +#### Stencil Copy Task + +[Stencil `copy` task](../output-targets/copy-tasks.md)s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a copy task can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```ts +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'your-component-library', + outputTargets: [ + { + type: 'dist-custom-elements', + copy: [ + { + src: '**/*.{jpg,png}', + dest: 'dist/components/assets', + warn: true, + } + ] + }, + ], + // ... +}; +``` +#### Rollup Configuration + +[Rollup Plugins](../config/plugins.md#rollup-plugins)'s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a the `rollup-plugin-copy` NPM module can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```javascript +import { Config } from '@stencil/core'; +import copy from 'rollup-plugin-copy'; + +export const config: Config = { + namespace: 'copy', + outputTargets: [ + { + type: 'dist-custom-elements', + }, + ], + rollupPlugins: { + after: [ + copy({ + targets: [ + { + src: 'src/**/*.{jpg,png}', + dest: 'dist/components/assets', + }, + ], + }), + ] + } +}; +``` + +## API Reference + +### getAssetPath + +`getAssetPath()` is an API provided by Stencil to build the path to an asset, relative to the asset base path. + +```ts +/** + * Builds a URL to an asset. This is achieved by combining the + * provided `path` argument with the base asset path. + * @param path the path of the asset to build a URL to + * @returns the built URL + */ +declare function getAssetPath(path: string): string; +``` + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments, when an asset base path of `/build/` has been set. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": +// "/build/" +getAssetPath(''); +// "/build/my-image.png" +getAssetPath('my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('assets/my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('./assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('../assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('/assets/my-image.png'); +``` + +### setAssetPath + +`setAssetPath` is an API provided by Stencil's runtime to manually set the asset base path where assets can be found. If you are using `getAssetPath` to compose the path for your component assets, `setAssetPath` allows you or the consumer of the component to change that path. + +```ts +/** + * Set the base asset path for resolving components + * @param path the base asset path + * @returns the new base asset path + */ +export declare function setAssetPath(path: string): string; +``` + +Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects when using a component. + +Make sure as component author to export this function as part of your module in order to also make it accessible to the consumer of your component, e.g. in your package entry file export the function via: + +```ts title="/src/index.ts" +export { setAssetPath } from '@stencil/core'; +``` + +Now your users can import it directly from your component library, e.g.: + +```ts +import { setAssetPath } from 'my-component-library'; +setAssetPath(`${window.location.protocol}//assets.${window.location.host}/`); +``` + +Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the +asset base path. This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. + +:::note + +If your component library exports components compiled with [`dist-output-target`](/output-targets/custom-elements.md) and `externalRuntime` set to `true`, then `setAssetPath` has to be imported from `@stencil/core` directly. + +::: + +In case you import a component directly via script tag, this would look like: + +```html + + + + + + + + + +``` diff --git a/versioned_docs/version-v4.18/guides/build-conditionals.md b/versioned_docs/version-v4.18/guides/build-conditionals.md new file mode 100644 index 000000000..0f540e8de --- /dev/null +++ b/versioned_docs/version-v4.18/guides/build-conditionals.md @@ -0,0 +1,41 @@ +--- +title: Build Conditionals +description: Build Conditionals +--- + +# Build Conditionals + +Build Conditionals in Stencil allow you to run specific code only when Stencil is running in development mode. This code is stripped from your bundles when doing a production build, therefore keeping your bundles as small as possible. + +### Using Build Conditionals + +Lets dive in and look at an example of how to use our build conditional: + +```tsx +import { Component, Build } from '@stencil/core'; + +@Component({ + tag: 'stencil-app', + styleUrl: 'stencil-app.css' +}) +export class StencilApp { + + componentDidLoad() { + if (Build.isDev) { + console.log('im in dev mode'); + } else { + console.log('im running in production'); + } + } +} +``` + +As you can see from this example, we just need to import `Build` from `@stencil/core` and then we can use the `isDev` constant to detect when we are running in dev mode or production mode. + +### Use Cases + +Some use cases we have come up with are: + +- Diagnostics code that runs in dev to make sure logic is working like you would expect +- `console.log()`'s that may be useful for debugging in dev mode but that you don't want to ship +- Disabling auth checks when in dev mode diff --git a/versioned_docs/version-v4.18/guides/csp-nonce.md b/versioned_docs/version-v4.18/guides/csp-nonce.md new file mode 100644 index 000000000..e18636cd8 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/csp-nonce.md @@ -0,0 +1,119 @@ +--- +title: Content Security Policy Nonces +description: How to leverage CSP nonces in Stencil projects. +slug: /csp-nonce +--- + +# Using Content Security Policy Nonces in Stencil + +[Content Security Policies (CSPs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) can help protect an application from Cross-Site Scripting (XSS) +attacks by adding a security layer to help prevent unauthorized code from running in the browser. + +An application that is served with a CSP other than 'unsafe-inline' and contains web components without a Shadow DOM will likely run into errors on load. +This is often first detected in the browser's console, which reports an error stating that certain styles or scripts violate the effective CSP. + +To resolve this issue, Stencil supports using [CSP nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) in +many of the output targets. + +:::caution +NOTE: CSPs and some CSP strategies are not supported by certain browsers. For a more detailed list, please see the [CSP browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#browser_compatibility). +::: + +## How to Use a Nonce + +The actual generation of the nonce value and enforcement of the correct CSP are not the responsibility of Stencil. Instead, the server of +the application will need to generate the nonce value for each page view, construct the CSP, and then correctly handle passing the generated nonce to +Stencil based on which output target is being consumed. + +There are many resources available that walk through setting up a CSP and using the nonce behavior. +[This](https://towardsdatascience.com/content-security-policy-how-to-create-an-iron-clad-nonce-based-csp3-policy-with-webpack-and-nginx-ce5a4605db90) +article walks through the process using Nginx and Webpack. Obviously, these resources don't account for the Stencil specifics, but any specifics will +be called out in this guide. + +Per the [MDN Guide on nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce#generating_values), a nonce should be "a random base64-encoded string of at least 128 bits of data from a cryptographically secure random number generator". + +### Output Targets + +Using nonces may differ slightly between output targets, so please be sure to use the correct pattern based on the context in which your +Stencil components are consumed. + +#### Dist + +Consuming a `nonce` in the `dist` output target is easy using the provided `setNonce` helper function. This function is exported from the index +file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); + +defineCustomElements(); +``` + +#### Custom Elements + +Consuming a `nonce` in the `dist-custom-elements` output target is easy using the provided `setNonce` helper function. This function is exported +from the index file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist-custom-elements` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/dist/components'; +// Assume `customElementsExportBehavior: 'auto-define-custom-elements'` is set +import 'my-lib/dist/components/my-component'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); +``` + +#### WWW + +Unfortunately, setting `nonce` attributes gets a bit trickier when it comes to [SSR and SSG](../static-site-generation/01-overview.md). As a `nonce` needs +to be unique per page view, it cannot be defined/set at build time. So, this responsibility now falls on the +[hydrate app](../guides/hydrate-app.md)'s execution of runtime code. + +**SSR** + +Since there is not an easy way (or any way) of exposing and executing helper functions to manipulate the outcome of the runtime code, Stencil +has fallback behavior for pulling the `nonce` off of a `meta` tag in the DOM head. + +So, for SSR, your app can simply inject a `meta` element into the header _on each page request_. Yes, this does involve some manual configuration +for the code served by your server. To work correctly, the created tag must be generated as follows: + +```html + +``` + +This isn't a security risk because, for an attacker to execute a script to pull the nonce from the meta tag, they would have needed to know the +nonce _ahead_ of the script's execution. + +**SSG** + +Stencil cannot support CSP nonces with SSG. Because all of the code is generated during [pre-rendering](../static-site-generation/01-overview.md#how-static-site-generation-and-prerendering-works), Stencil doesn't generate the `style` or `script` tags at runtime. +If an application wants to leverage nonces in SSG, they can build a mechanism to scrape the pre-rendered code and apply the attribute server-side before +it is served to the client. diff --git a/versioned_docs/version-v4.18/guides/design-systems.md b/versioned_docs/version-v4.18/guides/design-systems.md new file mode 100644 index 000000000..356f9dcbc --- /dev/null +++ b/versioned_docs/version-v4.18/guides/design-systems.md @@ -0,0 +1,77 @@ +--- +title: Design Systems +sidebar_label: Design Systems +description: Design Systems in Stencil +slug: /design-systems +--- + +# Design Systems + +## What is a Design System? + +A Design System consists of UI components and a clearly defined visual style, released as both code implementations and design artifacts. +When adopted by all product teams, a more cohesive customer experience emerges. + +There are several aspects that Design Systems consist of: + +### Components +A component is a standalone UI element designed to be reusable across many projects. +Its goal is to do one thing well, while remaining abstract enough to allow for a variety of use cases. +Developers can use them as building blocks to build new user experiences. +One of the key benefits of reusable components is that developers don't have to worry about the core design and functionality of each component every time they use them. +Examples include buttons, links, forms, input fields, and modals. + +### Patterns +A pattern is an opinionated use of components. +Often, multiple components are combined in order to create a standardized user experience (UX). +As a result, they improve both the user and developer experience. +After implementing patterns, users will understand the application better and accomplish their tasks faster. +When the development team understands the proper way to use components together, software applications become easier to use. +Examples include saving data to the system, capturing data from forms, and filtering and analyzing data. + +### Visual Language +A cohesive company brand strengthens its value in the minds of the customer. +In the context of design systems, this means defining various aspects of the visual style, including colors, typography, and icons. +Defining primary, secondary, and tertiary colors helps an application stand out and is more user-friendly. +The right typography ensures users are not distracted while using an app. +Finally, icons increase engagement in a product and make it “pop” visually. + +### Design Artifacts and Code Implementations +By leveraging the components, patterns, and visual language of the design system, designers can create design artifacts representing UI workflows. +Developers refer to the artifacts as guidance for implementing the design with code. + +## The Value of Design Systems +With a design system in place, its true value is revealed. +The entire product development team is freed up to focus on what matters most: solving customer problems and delivering value. +Additionally, the avoidance of having teams working in parallel, recreating the same UI elements over and over, has a real-world project impact in terms of reduced time to market and increased cost savings. + +Design systems allow project teams to work better together. +Designers define a centralized “source of truth” for software application best practices which can be referenced by anyone in a product organization. +Developers no longer need to spend time rethinking how to build common app scenarios, such as application search or data table grids. +When the business inevitably makes changes to the design system, they can easily be applied to all projects. +The end result is a better product for your users. + +## Using Stencil to Build a Design System + +There’s a lot that goes into creating amazing UI components. +Performance, accessibility, cross-platform capabilities, and user experience (not only of the UI component itself but how it fits into the entire design system) all must be considered. + +These aspects take real effort to do well. + +Enter Stencil, a robust and highly extensible tool for building components and patterns, the building blocks of a design system. +With its intentionally minimalistic tooling and API footprint, it’s simple to incorporate into your existing development workflows. +It brings substantial performance out of the box by leveraging a tiny runtime. +Most importantly, all UI components built with Stencil are based 100% on open web standards. + +### The Importance of Open Web Standards +By using the web components standard, supported in all modern browsers, Stencil-built UI components offer many distinct advantages for use in a design system, namely: + +* They work on any platform or device +* They work with any front-end framework, so they can easily be used across teams and projects using different tech stacks +* They facilitate the creation of one company-wide code implementation instead of one per framework or platform + +Learn more about why web components are ideal for design systems in [this blog post](https://blog.ionicframework.com/5-reasons-web-components-are-perfect-for-design-systems/). + +### How to Get Started +Stencil’s out-the-box features will help you build your own library of universal UI components that will work across platforms, devices, and front-end frameworks. +Review the documentation on this site to get started. diff --git a/versioned_docs/version-v4.18/guides/forms.md b/versioned_docs/version-v4.18/guides/forms.md new file mode 100644 index 000000000..555162b98 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/forms.md @@ -0,0 +1,165 @@ +--- +title: Forms +sidebar_label: Forms +description: Forms +slug: /forms +--- + +# Forms + +## Basic forms + +Here is an example of a component with a basic form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + + @State() value: string; + + handleSubmit(e) { + e.preventDefault() + console.log(this.value); + // send data to our backend + } + + handleChange(event) { + this.value = event.target.value; + } + + render() { + return ( +
    this.handleSubmit(e)}> + + +
    + ); + } +} +``` + +Let's go over what is happening here. First we bind the value of the input to a state variable, in this case `this.value`. We then set our state variable to the new value of the input with the `handleChange` method we have bound to `onInput`. `onInput` will fire every keystroke that the user types into the input. + +## Using form-associated custom elements + +In addition to using a `
    ` element inside of a Stencil component, as shown +in the above example, you can also use Stencil's support for building +form-associated custom elements to create a Stencil component that integrates +in a native-like way with a `` tag _around_ it. This allows you to build +rich form experiences using Stencil components which leverage built-in form +features like validation and accessibility. + +As an example, translating the above example to be a form-associated component +(instead of one which includes a `` element in its JSX) would look like +this: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css', + formAssociated: true +}) +export class MyName { + @State() value: string; + @AttachInternals() internals: ElementInternals; + + handleChange(event) { + this.internals.setFormValue(event.target.value); + } + + render() { + return ( + + ); + } +} +``` + +For more check out the docs for [form-association in Stencil](../components/form-associated.md). + +## Advanced forms + +Here is an example of a component with a more advanced form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + selectedReceiverIds = [102, 103]; + @State() value: string; + @State() selectValue: string; + @State() secondSelectValue: string; + @State() avOptions: any[] = [ + { 'id': 101, 'name': 'Mark' }, + { 'id': 102, 'name': 'Smith' } + ]; + + handleSubmit(e) { + e.preventDefault(); + console.log(this.value); + } + + handleChange(event) { + this.value = event.target.value; + + if (event.target.validity.typeMismatch) { + console.log('this element is not valid') + } + } + + handleSelect(event) { + console.log(event.target.value); + this.selectValue = event.target.value; + } + + handleSecondSelect(event) { + console.log(event.target.value); + this.secondSelectValue = event.target.value; + } + + render() { + return ( + this.handleSubmit(e)}> + + + + + + + +
    + ); + } +} +``` + +This form is a little more advanced in that it has two select inputs along with an email input. We also do validity checking of our email input in the `handleChange` method. We handle the `select` element in a very similar manner to how we handle text inputs. + +For the validity checking, we are #usingtheplatform and are using the [constraint validation api](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation) that is built right into the browser to check if the user is actually entering an email or not. diff --git a/versioned_docs/version-v4.18/guides/hydrate-app.md b/versioned_docs/version-v4.18/guides/hydrate-app.md new file mode 100644 index 000000000..d02fe0b1b --- /dev/null +++ b/versioned_docs/version-v4.18/guides/hydrate-app.md @@ -0,0 +1,117 @@ +--- +title: Hydrate App +sidebar_label: Hydrate App +description: Hydrate App +slug: /hydrate-app +--- + +# Hydrate App + +The hydrate app is a Stencil output target which generates a module that can be +used on a NodeJS server to hydrate HTML and implement server side rendering (SSR). +This functionality is used internally by the Stencil compiler for +prerendering, as well as for the Angular Universal SSR for the Ionic +framework. However, like Stencil components, the hydrate app itself is not +restricted to one framework. + +_Note that Stencil does **NOT** use Puppeteer for SSR or prerendering._ + +## How to Use the Hydrate App + +Server side rendering (SSR) can be accomplished in a similar way to +prerendering. Instead of using the `--prerender` CLI flag, you can an output +target of type `'dist-hydrate-script'` to your `stencil.config.ts`, like so: + +```ts +outputTargets: [ + { + type: 'dist-hydrate-script', + }, +]; +``` + +This will generate a `hydrate` app in your root project directory that can be +imported and used by your Node server. + +After publishing your component library, you can import the hydrate app into +your server's code like this: + +```javascript +import { hydrateDocument } from 'yourpackage/hydrate'; +``` + +The hydrate app module exports two functions, `hydrateDocument` and +`renderToString`. `hydrateDocument` takes a +[document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) as +its input while `renderToString` takes a raw HTML string. Both functions return +a Promise which wraps a result object. + +### hydrateDocument + +You can use `hydrateDocument` as a part of your server's response logic before +serving the web page. `hydrateDocument` takes two arguments, a +[document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) and a +config object. The function returns a promise with the hydrated results, with +the hydrated HTML under the `html` property. + +*Example taken from Ionic Angular server* + + ```javascript +import { hydrateDocument } from 'yourpackage/hydrate'; + +export function hydrateComponents(doc) { + return hydrateDocument(doc) + .then((hydrateResults) => { + // execute logic based on results + console.log(hydrateResults.html); + return hydrateResults; + }); +} +``` + +#### hydrateDocument Options + + - `canonicalUrl` - string + - `constrainTimeouts` - boolean + - `clientHydrateAnnotations` - boolean + - `cookie` - string + - `direction` - string + - `language` - string + - `maxHydrateCount` - number + - `referrer` - string + - `removeScripts` - boolean + - `removeUnusedStyles` - boolean + - `resourcesUrl` - string + - `timeout` - number + - `title` - string + - `url` - string + - `userAgent` - string + +### renderToString + +The hydrate app also has a `renderToString` function that takes an HTML string +and returns a promise of `HydrateResults`. The optional second parameter is a +config object that can alter the output of the markup. Like `hydrateDocument`, +the hydrated HTML can be found under the `html` property. + +*Example taken from Ionic Core* + +```javascript +const results = await hydrate.renderToString(srcHtml, { + prettyHtml: true, + removeScripts: true +}); + +console.log(results.html); +``` + +#### renderToString Options + + - `approximateLineWidth` - number + - `prettyHtml` - boolean + - `removeAttributeQuotes` - boolean + - `removeBooleanAttributeQuotes` - boolean + - `removeEmptyAttributes` - boolean + - `removeHtmlComments` - boolean + - `afterHydrate` - boolean + - `beforeHydrate` - boolean diff --git a/versioned_docs/version-v4.18/guides/module-bundling.md b/versioned_docs/version-v4.18/guides/module-bundling.md new file mode 100644 index 000000000..769bea76b --- /dev/null +++ b/versioned_docs/version-v4.18/guides/module-bundling.md @@ -0,0 +1,150 @@ +--- +title: Module Bundling +sidebar_label: Bundling +description: Module Bundling +slug: /module-bundling +--- + +# Module Bundling + +Stencil uses [Rollup](https://rollupjs.org/guide/en/) under the hood to bundle your components. This guide will explain and recommend certain workarounds for some of the most common bundling issues you might encounter. + +## One Component Per Module + +For Stencil to bundle your components most efficiently, you must declare a single component (class decorated with `@Component`) per *TypeScript* file, and the component itself **must** have a unique `export`. By doing so, Stencil is able to easily analyze the entire component graph within the app, and best understand how components should be bundled together. Under-the-hood it uses the Rollup bundler to efficiently bundled shared code together. Additionally, lazy-loading is a default feature of Stencil, so code-splitting is already happening automatically, and only dynamically importing components which are being used on the page. + +Modules that contain a component are entry-points, which means that no other module should import anything from them. + +The following example is **NOT** valid: + +```tsx title="src/components/my-cmp.tsx" +// This module has a component, you cannot export anything else +export function someUtilFunction() { + console.log('do stuff'); +} + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +In this case, the compiler will emit an error that looks like this: + +```bash +[ ERROR ] src/components/my-cmp.tsx:4:1 + To allow efficient bundling, modules using @Component() can only have a single export which is the component + class itself. Any other exports should be moved to a separate file. For further information check out: + https://stenciljs.com/docs/module-bundling + + L4: export function someUtilFunction() { + L5: console.log('do stuff'); +``` + +The solution is to move any shared functions or classes to a different `.ts` file, like this: + +```tsx title="src/utils.ts" +export function someUtilFunction() { + console.log('do stuff'); +} +``` + +```tsx title="src/components/my-cmp.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +```tsx title="src/components/my-cmp-two.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp-two' +}) +export class MyCmpTwo {} +``` + + +## CommonJS Dependencies + +Rollup depends on [ES modules (ESM)](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) to properly tree-shake the module graph, unfortunately, some third-party libraries ship their code using the [CommonJS](https://requirejs.org/docs/commonjs.html) module system, which is not ideal. + +Since CommonJS libraries are still common today, Stencil comes with [`rollup-plugin-commonjs`](https://github.com/rollup/rollup-plugin-commonjs) already installed and configured. + +At compiler-time, the `rollup-plugin-commonjs` plugin does a best-effort to **transform CommonJS into ESM**, but this is not always an easy task. CommonJS is dynamic by nature, while ESM is static by design. + +For further information, check out the [rollup-plugin-commonjs docs](https://github.com/rollup/plugins/tree/master/packages/commonjs). + + + +## Custom Rollup plugins + +Stencil provides an API to pass custom rollup plugins to the bundling process in `stencil.config.ts`. Under the hood, stencil ships with some built-in plugins including `node-resolve` and `commonjs`, since the execution order of some rollup plugins is important, stencil provides an API to inject custom plugin **before node-resolve** and after **commonjs transform**: + +```tsx +export const config = { + rollupPlugins: { + before: [ + // Plugins injected before rollupNodeResolve() + resolvePlugin() + ], + after: [ + // Plugins injected after commonjs() + nodePolyfills() + ] + } +} +``` + +As a rule of thumb, plugins that need to resolve modules, should be place in `before`, while code transform plugins like: `node-polyfills`, `replace`... should be placed in `after`. Follow the plugin's documentation to make sure it's executed in the right order. + + +## Node Polyfills + +Depending on which libraries a project is dependent on, the [rollup-plugin-node-polyfills](https://www.npmjs.com/package/rollup-plugin-node-polyfills) plugin may be required. In such cases, an error message similar to the following will be displayed at build time. + +```bash +[ ERROR ] Bundling Node Builtin + For the import "crypto" to be bundled from 'problematic-dep', + ensure the "rollup-plugin-node-polyfills" plugin is installed + and added to the stencil config plugins. +``` + +This is caused by some third-party dependencies that use [Node APIs](https://nodejs.org/dist/latest-v10.x/docs/api/) that are not available in the browser, the `rollup-plugin-node-polyfills` plugin works by transparently polyfilling this missing APIs in the browser. + +### 1. Install `rollup-plugin-node-polyfills`: + +```bash npm2yarn +npm install rollup-plugin-node-polyfills --save-dev +``` + +### 2. Update the `stencil.config.ts` file including the plugin: + +```tsx +import { Config } from '@stencil/core'; +import nodePolyfills from 'rollup-plugin-node-polyfills'; + +export const config: Config = { + namespace: 'mycomponents', + rollupPlugins: { + after: [ + nodePolyfills(), + ] + } +}; +``` + +:::note +`rollup-plugin-node-polyfills` is a code-transform plugin, so it needs to run AFTER the commonjs transform plugin, that's the reason it's placed in the "after" array of plugins. +::: + +## Strict Mode + +ES modules are always parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's nothing we can do about that. + +Luckily, there is absolutely no good reason not to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them. + +*Source: [https://github.com/rollup/rollup-plugin-commonjs#strict-mode](https://github.com/rollup/rollup-plugin-commonjs#strict-mode)* diff --git a/versioned_docs/version-v4.18/guides/publishing.md b/versioned_docs/version-v4.18/guides/publishing.md new file mode 100644 index 000000000..1c4acdf01 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/publishing.md @@ -0,0 +1,159 @@ +--- +title: Publishing A Component Library +sidebar_label: Publishing +description: Publishing A Component Library +slug: /publishing +--- + +There are numerous strategies to publish and distribute your component library to be consumed by external projects. One of the benefits of Stencil is that is makes it easy to generate the various [output targets](../output-targets/01-overview.md) that are right for your use-case. + +## Use Cases + +To use your Stencil components in other projects, there are two different output targets to consider: [`dist`](../output-targets/dist.md) and [`dist-custom-elements`](../output-targets/custom-elements.md). Both export your components for different use cases. Luckily, both can be generated at the same time, using the same source code, and shipped in the same distribution. It would be up to the consumer of your component library to decide which build to use. + +### Lazy Loading + +If you prefer to have your components automatically loaded when used in your application, we recommend enabling the [`dist`](../output-targets/dist.md) output target. The bundle gives you a small entry file that registers all your components and defers loading the full component logic until it is rendered in your application. It doesn't matter if the actual application is written in HTML or created with vanilla JavaScript, jQuery, React, etc. + +Your users can import your component library, e.g. called `my-design-system`, either via a `script` tag: + +```html + +``` + +or by importing it in the bootstrap script of your application: + +```ts +import 'my-design-system'; +``` + +To ensure that the right entry file is loaded when importing the project, define the following fields in your `package.json`: + +```json +{ + "exports": "./dist/esm/my-design-system.js", + "main": "./dist/cjs/my-design-system.js", + "unpkg": "dist/my-design-system/my-design-system.esm.js", +} +``` + +Read more about various options when it comes to configuring your project's components for lazy loading in the [`dist`](../output-targets/dist.md) output target section. + +#### Considerations + +To start, Stencil was designed to lazy-load itself only when the component was actually used on a page. There are many benefits to this approach, such as simply adding a script tag to any page and the entire library is available for use, yet only the components actually used are downloaded. For example, [`@ionic/core`](https://www.npmjs.com/package/@ionic/core) comes with over 100 components, but a webpage may only need `ion-toggle`. Instead of requesting the entire component library, or generating a custom bundle for just `ion-toggle`, the `dist` output target is able to generate a tiny entry build ready to load any of its components on-demand. + +However be aware that this approach is not ideal in all cases. It requires your application to ship the bundled components as static assets in order for them to load properly. Furthermore, having many nested component dependencies can have an impact on the performance of your application. For example, given you have a component `CmpA` which uses a Stencil component `CmpB` which itself uses another Stencil component `CmpC`. In order to fully render `CmpA` the browser has to load 3 scripts sequentially which can result in undesired rendering delays. + +### Standalone + +The [`dist-custom-elements`](../output-targets/custom-elements.md) output target builds each component as a stand-alone class that extends `HTMLElement`. The output is a standardized custom element with the styles already attached and without any of Stencil's lazy-loading. This may be preferred for projects that are already handling bundling, lazy-loading and defining the custom elements themselves. + +The generated files will each export a component class and will already have the styles bundled. However, this build does not define the custom elements or apply any polyfills. Static assets referenced within components will need to be set using `setAssetPath` (see [Making Assets Available](../output-targets/custom-elements.md#making-assets-available)). + +You can use these standalone components by importing them via: + +```ts +import { MyComponent, defineCustomElementMyComponent } from 'my-design-system' + +// register to CustomElementRegistry +defineCustomElementMyComponent() + +// or extend custom element via +class MyCustomComponent extends MyComponent { + // ... +} +define('my-custom-component', MyCustomComponent) +``` + +To ensure that the right entry file is loaded when importing the project, define different [exports fields](https://nodejs.org/api/packages.html#exports) in your `package.json`: + +```json +{ + "exports": { + ".": { + "import": "./dist/components/index.js", + "types": "./dist/components/index.d.ts" + }, + "./my-component": { + "import": "./dist/components/my-component.js", + "types": "./dist/components/my-component.d.ts" + } + }, + "types": "dist/components/index.d.ts", +} +``` + +This allows us to map certain import paths to specific components within our project and allows users to only import the component code they are interested in and reduce the amount of code that needs to downloaded by the browser, e.g.: + +```js +// this import loads all compiled components +import { MyComponent } from 'my-design-system' +// only import compiled code for MyComponent +import { MyComponent } from 'my-design-system/my-component' +``` + +If you define exports targets for all your components as shown above and by using [`customElementsExportBehavior: 'auto-define-custom-elements'`](../output-targets/custom-elements.md#customelementsexportbehavior) as output target option, you can skip the `defineCustomElement` call and directly import the component where you need it: + +```ts +import 'my-design-system/my-component' +``` + +:::note +If you are distributing both the `dist` and `dist-custom-elements`, then it's best to pick one of them as the main entry depending on which use case is more prominent. +::: + +Read more about various options when it comes to distributing your components as standalone components in the [`dist-custom-elements`](../output-targets/custom-elements.md) output target section. + +The output directory will also contain an `index.js` file which exports some helper methods by default. The contents of the file will look something like: + +```js +export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client'; +``` + +:::note +The contents may look different if [`customElementsExportBehavior`](../output-targets/custom-elements.md#customelementsexportbehavior) is specified! +::: + +#### Considerations + +The `dist-custom-elements` is a direct build of the custom element that extends `HTMLElement`, without any lazy-loading. This distribution strategy may be preferred for projects that use an external bundler such as [Vite](https://vitejs.dev/), [WebPack](https://webpack.js.org/) or [Rollup](https://rollupjs.org) to compile the application. They ensure that only the components used within your application are bundled into compilation. + +#### Usage in TypeScript + +If you plan to support consuming your component library in TypeScript you'll need to set `generateTypeDeclarations: true` on the output target in your `stencil.config.ts`, like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + generateTypeDeclarations: true, + }, + // ... + ], + // ... +}; +``` + +Then you can set the `types` property in `package.json` so that consumers of your package can find the type definitions, like so: + +```json title="package.json" +{ + "types": "dist/components/index.d.ts", + "dependencies": { + "@stencil/core": "latest" + }, + ... +} +``` + +:::note +If you set the `dir` property on the output target config, replace `dist/components` in the above snippet with the path set in the config. +::: + +## Publishing to NPM + +[NPM](https://www.npmjs.com/) is an online software registry for sharing libraries, tools, utilities, packages, etc. To make your Stencil project widely available to be consumed, it's recommended to [publish the component library to NPM](https://docs.npmjs.com/getting-started/publishing-npm-packages). Once the library is published to NPM, other projects are able to add your component library as a dependency and use the components within their own projects. diff --git a/versioned_docs/version-v4.18/guides/service-workers.md b/versioned_docs/version-v4.18/guides/service-workers.md new file mode 100644 index 000000000..51f37237a --- /dev/null +++ b/versioned_docs/version-v4.18/guides/service-workers.md @@ -0,0 +1,293 @@ +--- +title: Service Workers +sidebar_label: Service Workers +description: Service Workers +slug: /service-workers +--- + +# Service Workers + +[Service workers](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers) are a very powerful api that is essential for [PWAs](https://blog.ionic.io/what-is-a-progressive-web-app/), but can be hard to use. To help with this, we decided to build support for Service Workers into Stencil itself using [Workbox](https://workboxjs.org/). + +## What is Workbox? + +Workbox is a library that greatly simplifies the Service Worker API. It allows you to quickly generate a service worker that can handle caching static assets, cache remote assets using routes (similar to Express) or even do offline Google Analytics. Because we are built on top of Workbox, you can easily use any of the functionality they offer. For more info on Workbox, [check out their docs](https://developers.google.com/web/tools/workbox/) + +## Usage + +When doing a production build of an app built using Stencil, the Stencil compiler will automatically generate a service worker for you and inject the necessary code to register the service worker in your index.html. Also, because the files Stencil generates are hashed, every time you do a production build and push an update to your app, the service worker will know to update, therefore ensuring your users are never stuck on a stale version of your site. + +Lets run through the steps needed to enable service workers for your project: + +- `cd` into your project +- Run `npm run build` + +And that's it! You should now have an `sw.js` file in your `www` folder and the code to register the service worker in your `www/index.html` file. + +:::note +The component starter by default does not have service workers enabled as a service worker is not needed for component collections +::: + +## Config + +Stencil uses Workbox underneath, and by default generates a service worker from a config object using the `generateSW` mode. Therefore it supports all of the [Workbox generateSW config options](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). Here is the default config Stencil uses: + +```tsx +{ + globPatterns: [ + '**/*.{js,css,json,html}' + ] +}; +``` + +This configuration does pre-caching of all of your app's assets. + +To modify this config you can use the `serviceWorker` param of your Stencil config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + globPatterns: [ + '**/*.{js,css,json,html,ico,png}' + ] + } + } + ] +}; +``` + +### Disabling the service worker + +If you do not want a service worker to be generated during the build, this can be turned off. To disable this feature, set the `serviceWorker` property to `null` in the `www` output target. + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: null + } + ] +}; +``` + +## Using a custom service worker + +Already have a service worker or want to include some custom code? We support that, too. By specifying a source file for your service worker, Stencil switches to the `injectManifest` mode of Workbox. That gives you full control over your service worker, while still allowing you to automatically inject a precache manifest. + +Let's go through the steps needed for this functionality: + +- First we need to pass the path to our custom service worker to the `swSrc` command in the `serviceWorker` config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + swSrc: 'src/sw.js' + } + } + ] +}; +``` + +- Now we need to include some boilerplate code in our custom service worker: + +```tsx +// change to the version you get from `npm ls workbox-build` +importScripts('workbox-v4.3.1/workbox-sw.js'); + +// your custom service worker code + +// the precache manifest will be injected into the following line +self.workbox.precaching.precacheAndRoute([]); +``` + +This code imports the Workbox library, creates a new instance of the service worker and tells Workbox where to insert the pre-cache array. + +### Showing a reload toast when an update is available + +When a new service worker is available, by default, it will be downloaded and then go into a state of waiting to be activated. The new service worker won't take over until all tabs of the site are closed and the site is visited again. This is to avoid unexpected behavior from conflicts with files being served from cache, and works well in many cases. + +If you want to give your users the option to immediately access the new update, a common way is to show them a toast that lets them know about the update and offers a "reload" button. The reload let's the new service worker take over, serving the fresh content, and triggers a page reload, to avoid cache issues. + +The following example showcases this in combination with the Ionic framework, but the toast-related code should be easily adaptable to any UI. Add the following to your root component (commonly `app-root.tsx`). + +```tsx +@Listen("swUpdate", { target: 'window' }) +async onServiceWorkerUpdate() { + const registration = await navigator.serviceWorker.getRegistration(); + + if (!registration?.waiting) { + // If there is no waiting registration, this is the first service + // worker being installed. + return; + } + + const toast = await toastController.create({ + message: "New version available.", + buttons: [{ text: 'Reload', role: 'reload' }], + duration: 0 + }); + + await toast.present(); + + const { role } = await toast.onWillDismiss(); + + if (role === 'reload') { + registration.waiting.postMessage("skipWaiting"); + } +} +``` + +The `swUpdate` event is emitted by Stencil every time a new service worker is installed. When a service worker is waiting for registration, the toast is shown. After clicking the reload button, a message is posted to the waiting service worker, letting it know to take over. This message needs to be handled by the service worker; therefore we need to create a custom one (e. g. `src/sw.js`) and add a listener to call `skipWaiting()`. + +```tsx +importScripts("workbox-v4.3.1/workbox-sw.js"); + +self.addEventListener("message", ({ data }) => { + if (data === "skipWaiting") { + self.skipWaiting(); + } +}); + +self.workbox.precaching.precacheAndRoute([]); +``` + +:::note +Don't forget to set `swSrc` in your Stencil config. +::: + +Finally, we want our app to reload when the new service worker has taken over, so that no outdated code is served from the cache anymore. We can use the service worker's `controllerchange` event for that, by attaching an event listener in our root component's `componentWillLoad` lifecycle hook. + +```tsx +componentWillLoad() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker + .getRegistration() + .then(registration => { + if (registration?.active) { + navigator.serviceWorker.addEventListener( + 'controllerchange', + () => window.location.reload() + ); + } + }) + } +} +``` + +### Handle push events + +A common use case for custom service workers is to handle browser push notifications. But before we will be able show push notifications, we first need to use the Notifications API to request permissions from the user to do so. + +```tsx +if ('Notification' in window && 'serviceWorker' in navigator) { + Notification.requestPermission(status => { + // status will either be 'default', 'granted' or 'denied' + console.log(`Notification permissions have been ${status}`); + }); +} +``` + +The current permission status can always be checked using `Notification.permission`. + +To show a notification to the user after being granted permission, we can use the `showNotification` method of our service worker's registration (within our custom service worker). + +```tsx +self.registration.showNotification('Hakuna matata.'); +``` + +Usually we will have a backend that will send out push notifications to clients, and we want our service worker to handle them. To do that, we can register an event listener in our worker for the `push` event. The event will be of type [`PushEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent) and have a `data` field of type [`PushMessageData`](https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData). + +```tsx +self.addEventListener('push', event => { + console.log(`Push received with data "${event.data.text()}"`); + + const title = 'Push Notification'; + const options = { + body: `${event.data.text()}`, + data: { href: '/users/donald' }, + actions: [ + { action: 'details', title: 'Details' }, + { action: 'dismiss', title: 'Dismiss' }, + ], + }; + + event.waitUntil(self.registration.showNotification(title, options)); +}); +``` + +If the data is a JSON string, then `data.json()` can be used to immediately get the parsed data. The `event.waitUntil` method is used to ensure that the service worker doesn't terminate before the asynchronous `showNotification` operation has completed. + +Furthermore, we will likely want to handle notification clicks. The API provides the events `notificationclick` and `notificationclose` for that. + +```tsx +self.addEventListener('notificationclick', event => { + const notification = event.notification; + const action = event.action; + + if (action === 'dismiss') { + notification.close(); + } else { + // This handles both notification click and 'details' action, + // because some platforms might not support actions. + clients.openWindow(notification.data.href); + notification.close(); + } +}); +``` + +Now our service worker is able to receive and process push notifications, however we still need to register the client with our backend. Browsers provide a push service for that reason, which your app can subscribe to. The subscription object contains an endpoint URL with a unique identifier for each client. You can send your notifications to that URL, encrypted with a public key which is also provided by the subscription object. + +In order to implement this, we first need to get each client to subscribe to the browser's push service, and then send the subscription object to our backend. Then our backend can generate the push notifications, encrypt them with the public key, and send them to the subscription endpoint URL. + +First we will implement a function to subscribe the user to the push service, which as a best practice should be triggered from a user action signalling that they would like to receive push notifications. Assuming that notification permissions have already been granted, the following function can be used for that. + +```tsx +async function subscribeUser() { + if ('serviceWorker' in navigator) { + const registration = await navigator.serviceWorker.ready; + + const subscription = await registration.pushManager + .subscribe({ userVisibleOnly: true }) + .catch(console.error); + + if (!subscription) { + return; + } + + // the subscription object is what we want to send to our backend + console.log(subscription.endpoint); + } +} +``` + +We should also check our subscription every time our app is accessed, because the subscription object can change. + +```tsx +self.registration.pushManager.getSubscription().then(subscription => { + if (!subscription) { + // ask the user to register for push + return; + } + + // update the database + console.log(subscription); +}); +``` + +### Further Reading + +* For more information on push notifications and the related APIs please refer to the [Web Fundamentals Introduction to Push Notifications](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications) and the [MDN Push API docs](https://developer.mozilla.org/en-US/docs/Web/API/Push_API). +* [This Twitter thread by David Brunelle](https://twitter.com/davidbrunelle/status/1073394572980453376) explains how to implement versioning in your PWA in order to handle breaking API changes. The problem here is that your service worker enabled app will continue to serve an outdated (cached) app against your updated API. In order to solve this a version check can be implemented. diff --git a/versioned_docs/version-v4.18/guides/store.md b/versioned_docs/version-v4.18/guides/store.md new file mode 100644 index 000000000..b293435ab --- /dev/null +++ b/versioned_docs/version-v4.18/guides/store.md @@ -0,0 +1,131 @@ +--- +title: 'Store' +sidebar_label: Stencil Store +description: Store +slug: /stencil-store +--- + +# @stencil/store + +[Store](https://github.com/ionic-team/stencil-store) is a lightweight shared state library by the stencil core team. It implements a simple key/value map that efficiently re-renders components when necessary. + +- Lightweight +- Zero dependencies +- Simple API, like a reactive Map +- Best performance + +## Installation + +```bash npm2yarn +npm install @stencil/store --save-dev +``` + +## Example + +**store.ts:** + +```tsx +import { createStore } from "@stencil/store"; + +const { state, onChange } = createStore({ + clicks: 0, + seconds: 0, + squaredClicks: 0 +}); + +onChange('clicks', value => { + state.squaredClicks = value ** 2; +}); + +export default state; +``` + +**component.tsx:** + +```tsx +import { Component, h } from '@stencil/core'; +import state from '../store'; + +@Component({ + tag: 'app-profile', +}) +export class AppProfile { + + componentWillLoad() { + setInterval(() => state.seconds++, 1000); + } + + render() { + return ( +
    +

    + +

    + Seconds: {state.seconds} +
    + Squared Clicks: {state.squaredClicks} +

    +

    +
    + ); + } +} + +const MyGlobalCounter = () => { + return ( + + ); +}; +``` + +## API + +### `createStore(initialState)` + +Create a new store with the given initial state. The type is inferred from `initialState`, or can be passed as the generic type `T`. + +Returns a `store` object with the following properties. + +### `store.state` + +The state object is proxied, I.E. you can directly get and set properties and Store will automatically take care of component re-rendering when the state object is changed. + +### `store.on(event, listener)` + +Add a listener to the store for a certain action. + +### `store.onChange(propName, listener)` + +Add a listener that is called when a specific property changes. + +### `store.get(propName)` + +Get a property's value from the store. + +### `store.set(propName, value)` + +Set a property's value in the store. + +### `store.reset()` + +Reset the store to its initial state. + +### `store.use(...subscriptions)` + +Use the given subscriptions in the store. A subscription is an object that defines one or more of the properties `get`, `set` or `reset`. + + +## Testing + +Like any global state library, state should be reset between each spec test. +Use the `dispose()` API in the `beforeEach` hook. + +```ts +import store from '../store'; + +beforeEach(() => { + store.dispose(); +}); +``` diff --git a/versioned_docs/version-v4.18/guides/style-guide.md b/versioned_docs/version-v4.18/guides/style-guide.md new file mode 100644 index 000000000..1f18b31d1 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/style-guide.md @@ -0,0 +1,269 @@ +--- +title: Stencil Style Guide +sidebar_label: Style Guide +description: Stencil Style Guide +slug: /style-guide +--- + +# Stencil Style Guide + +This is a component style guide created and enforced internally by the core team of Stencil, for the purpose of standardizing Stencil components. This should only be used as a reference for other teams in creating their own style guides. Feel free to modify to your team's own preference. + +:::note +In order to enforce this (or your team's) style guide, we recommend leveraging a static analysis tool like [ESLint](https://eslint.org/). [@stencil-community/eslint-plugin](https://www.npmjs.com/package/@stencil-community/eslint-plugin) provides rules specifically for writing Stencil components. +::: + +:::note +This guide once recommended TSLint as a static analysis tool. TSLint has been deprecated by its maintaining organization in favor of ESLint and is no longer recommended by the Stencil team. +::: + +## File structure + +- One component per file. +- One component per directory. Though it may make sense to group similar components into the same directory, we've found it's easier to document components when each one has its own directory. +- Implementation (.tsx) and styles of a component should live in the same directory. + +Example from ionic-core: + +```bash +├── my-card +│ ├── my-card.ios.css +│ ├── my-card.md.css +│ ├── my-card.css +│ ├── my-card.tsx +│ └── test +│ └── basic +│ ├── e2e.js +│ └── index.html +├── my-card-content +│ ├── my-card-content.ios.css +│ ├── my-card-content.md.css +│ ├── my-card-content.css +│ └── my-card-content.tsx +├── my-card-title +│ ├── my-card-title.ios.css +│ ├── my-card-title.md.css +│ ├── my-card-title.css +``` + + +## Naming +### HTML tag + +#### Prefix +The prefix has a major role when you are creating a collection of components intended to be used across different projects, like [@ionic/core](https://www.npmjs.com/package/@ionic/core). Web Components are not scoped because they are globally declared within the webpage, which means a "unique" prefix is needed to prevent collisions. The prefix also helps to quickly identify the collection a component is part of. Additionally, web components are required to contain a "-" dash within the tag name, so using the first section to namespace your components is a natural fit. + +We do not recommend using "stencil" as prefix, since Stencil DOES NOT emit stencil components, but rather the output is standards compliant web components. + +DO NOT do this: +```markup + + +``` + +Instead, use your own naming or brand. For example, [Ionic](https://ionicframework.com/) components are all prefixed with `ion-`. +```markup + + +``` + +#### Name + +Components are not actions, they are conceptually "things". It is better to use nouns instead of verbs, such as "animation" instead of "animating". "input", "tab", "nav", "menu" are some examples. + + +#### Modifiers + +When several components are related and/or coupled, it is a good idea to share the name, and then add different modifiers, for example: + +```markup + + + +``` + + +### Component (TS class) + +The name of the ES6 class of the component SHOULD NOT have a prefix since classes are scoped. There is no risk of collision. + +```tsx +@Component({ + tag: 'ion-button' +}) +export class Button { ... } + +@Component({ + tag: 'ion-menu' +}) +export class Menu { ... } +``` + + +## TypeScript + +1. **Use private variables and methods as much possible:** They are useful to detect dead code and enforce encapsulation. Note that this is a feature which TypeScript provides to help harden your code, but using `private`, `public` or `protected` does not make a difference in the actual JavaScript output. + +2. **Code with Method/Prop/Event/Component decorators should have JSDocs:** This allows for documentation generation and for better user experience in an editor that has TypeScript intellisense + +## Code organization + +**Newspaper Metaphor from The Robert C. Martin's _Clean Code_** + +:::note +The source file should be organized like a newspaper article, with the highest level summary at the top, and more and more details further down. Functions called from the top function come directly below it, and so on down to the lowest level and most detailed functions at the bottom. This is a good way to organize the source code, even though IDEs make the location of functions less important, since it is so easy to navigate in and out of them. +::: + +### High level example (commented) + +```tsx +@Component({ + tag: 'ion-something', + styleUrls: { + ios: 'something.ios.css', + md: 'something.md.css', + wp: 'something.wp.css' + } +}) +export class Something { + + /** + * 1. Own Properties + * Always set the type if a default value has not + * been set. If a default value is being set, then type + * is already inferred. List the own properties in + * alphabetical order. Note that because these properties + * do not have the @Prop() decorator, they will not be exposed + * publicly on the host element, but only used internally. + */ + num: number; + someText = 'default'; + + /** + * 2. Reference to host HTML element. + * Inlined decorator + */ + @Element() el: HTMLElement; + + /** + * 3. State() variables + * Inlined decorator, alphabetical order. + */ + @State() isValidated: boolean; + @State() status = 0; + + /** + * 4. Public Property API + * Inlined decorator, alphabetical order. These are + * different than "own properties" in that public props + * are exposed as properties and attributes on the host element. + * Requires JSDocs for public API documentation. + */ + @Prop() content: string; + @Prop() enabled: boolean; + @Prop() menuId: string; + @Prop() type = 'overlay'; + + /** + * Prop lifecycle events SHOULD go just behind the Prop they listen to. + * This makes sense since both statements are strongly connected. + * - If renaming the instance variable name you must also update the name in @Watch() + * - Code is easier to follow and maintain. + */ + @Prop() swipeEnabled = true; + + @Watch('swipeEnabled') + swipeEnabledChanged(newSwipeEnabled: boolean, oldSwipeEnabled: boolean) { + this.updateState(); + } + + /** + * 5. Events section + * Inlined decorator, alphabetical order. + * Requires JSDocs for public API documentation. + */ + @Event() ionClose: EventEmitter; + @Event() ionDrag: EventEmitter; + @Event() ionOpen: EventEmitter; + + /** + * 6. Component lifecycle events + * Ordered by their natural call order, for example + * WillLoad should go before DidLoad. + */ + connectedCallback() {} + disconnectedCallback() {} + componentWillLoad() {} + componentDidLoad() {} + componentShouldUpdate(newVal: any, oldVal: any, propName: string) {} + componentWillUpdate() {} + componentDidUpdate() {} + componentWillRender() {} + componentDidRender() {} + + /** + * 7. Listeners + * It is ok to place them in a different location + * if makes more sense in the context. Recommend + * starting a listener method with "on". + * Always use two lines. + */ + @Listen('click', { enabled: false }) + onClick(ev: UIEvent) { + console.log('hi!') + } + + /** + * 8. Public methods API + * These methods are exposed on the host element. + * Always use two lines. + * Public Methods must be async. + * Requires JSDocs for public API documentation. + */ + @Method() + async open(): Promise { + // ... + return true; + } + + @Method() + async close(): Promise { + // ... + } + + /** + * 9. Local methods + * Internal business logic. These methods cannot be + * called from the host element. + */ + prepareAnimation(): Promise { + // ... + } + + updateState() { + // ... + } + + /** + * 10. render() function + * Always the last public method in the class. + * If private methods present, they are below public methods. + */ + render() { + return ( + + + + ); + } +} +``` diff --git a/versioned_docs/version-v4.18/guides/typed-components.md b/versioned_docs/version-v4.18/guides/typed-components.md new file mode 100644 index 000000000..243efed31 --- /dev/null +++ b/versioned_docs/version-v4.18/guides/typed-components.md @@ -0,0 +1,46 @@ +--- +title: Typed Components +sidebar_label: Typed Components +description: Typed Components +slug: /typed-components +--- + +# Typed Components + +Web Components generated with Stencil come with type declaration files automatically generated by the Stencil compiler. + +In general, TypeScript declarations provide strong guarantees when consuming components: + +- Ensuring that proper values are passed down as properties +- Code autocompletion in modern IDEs such as VSCode +- Events' details +- Signature of components' methods + +These public types are automatically generated by Stencil in `src/component.d.ts`. +This file allows for strong typing in JSX (just like React) and `HTMLElement` interfaces for each component. + +:::tip +It is recommended that this file be checked in with the rest of your code in source control. +::: + +Because Web Components generated by Stencil are just vanilla Web Components, they extend the `HTMLElement` interface. +For each component a type named `HTML{CamelCaseTag}Element` is registered at the global scope. +This means developers DO NOT have to import them explicitly, just like `HTMLElement` or `HTMLScriptElement` are not imported. + +- `ion-button` => `HTMLIonButtonElement` +- `ion-menu-controller` => `HTMLIonMenuControllerElement` + +```tsx +const button: HTMLIonButtonElement = document.queryElement('ion-button'); +button.fill = 'outline'; +``` + +**IMPORTANT**: always use the `HTML{}Element` interfaces in order to hold references to components. + +## Properties + +This section has moved to [Property Types](../components/properties.md#types) + +### Required Properties + +This section has moved to [Required Properties](../components/properties.md#required-properties) diff --git a/versioned_docs/version-v4.18/guides/vs-code-debugging.md b/versioned_docs/version-v4.18/guides/vs-code-debugging.md new file mode 100644 index 000000000..835a3b66a --- /dev/null +++ b/versioned_docs/version-v4.18/guides/vs-code-debugging.md @@ -0,0 +1,126 @@ +--- +title: Debugging With VS Code +sidebar_label: VS Code Debugging +description: How to debug a Stencil component using VS Code +slug: /vs-code-debugging +--- + +# Debugging With VS Code + +VS Code offers a streamlined debugging experience that can be started with a single click when using [launch configurations](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations). + +If you're unfamiliar with using the VS Code debugger in general, please visit the [VS Code debugger documentation](https://code.visualstudio.com/docs/editor/debugging) for a primer. + +## Requirements for Debugging + +In order for a debugger to function, the Stencil project must be configured to generate source maps for the compiled web components back to the source code. As of Stencil v3, source maps are generated by default, but be sure to double-check the project's Stencil config does not disable this behavior. More information regarding source maps in Stencil can be found in the [project configuration documentation](../config/01-overview.md#sourcemap). + +## Debugging Stencil Components In a Web App + +It's a common use case to want to step through a web component's code as it executes in the browser and VS Code makes that process simple. Combining the debugger with Stencil's dev server in watch mode will allow you to debug changes as they're made. + +### Configuring the VS Code Debugger + +To debug Stencil components as they run in a browser (web app), create (or edit) the `.vscode/launch.json` file with the following configuration: + +```json title=".vscode/launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3333", + "sourceMaps": true, + "sourceMapPathOverrides": { + "*": "${webRoot}/*" + } + } + ] +} +``` + +:::note +If your Stencil project is within a monorepo structure, you may want (or need) to add the `webRoot` option to the above config to point to the Stencil project's directory. For instance, if you have your Stencil project at `/packages/stencil-library`, you would add the following to the config: + +```json +{ + ..., + "webRoot": "${workspaceFolder}/packages/stencil-library", +} +``` + +::: + +This will create a configuration to open a Chrome debugger instance on port 3333 (the default port used by the Stencil dev server). To use this configuration, start a Stencil dev server (running `npm start` in a [Stencil component starter project](https://stenciljs.com/docs/getting-started)) and then run the configuration from the VS Code debugger tab. At this point, any breakpoints set in the component source code will pause browser execution when hit. + +:::note +If your Stencil project is [configured to use a different port](https://stenciljs.com/docs/dev-server#dev-server-config) for the dev server, you will need to update the `url` property in the debugger configuration with the correct port. +::: + +## Debugging Static Site Generation (SSG) + +Static Site Generation, also known as prerendering, executes your components at build time to generate a snapshot of the rendered styles and markup to be efficiently served to search engines and users on first request. + +Since this step runs in a Node.js process instead of a browser, debugging can't be done directly in the browser. However, debugging is straightforward using existing Node.js debugging techniques. + +### Overview + +The `stencil build --prerender` command will first build the hydrate script for a NodeJS environment, then prerender the site using the build. For a production build this is probably ideal. + +However, while debugging you may not need to keep rebuilding the hydrate script, but you only need to debug through the prerendering process. Stencil creates a file in `dist/hydrate` that is used to actually execute your components. + +To only prerender (and avoid rebuilding), you can use the `stencil prerender dist/hydrate/index.js` command, with the path to the script as a flag. + +### Tips for Debugging Prerendering + +By default, prerendering will start by rendering the homepage, find links within the homepage, and continue to crawl the entire site as it finds more links. While debugging, it might be easier to _not_ crawl every URL in the site, but rather have it only prerender one page. To disable crawling, set the prerender config `crawlUrls: false`. + +Next, you can use the `entryUrls` config to provide an array of paths to prerender, rather than starting at the homepage. + +Additionally, console logs that are printed within the runtime are suppressed while prerendering (otherwise the terminal would be overloaded with logs). By setting `runtimeLogging: true`, the runtime console logs will be printed in the terminal. Below is an example setup for prerender debugging: + +```tsx title="prerender.config.ts" +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + crawlUrls: false, + entryUrls: ['/example'], + hydrateOptions: (_url) => { + return { + runtimeLogging: true, + }; + }, +}; +``` + +### Configuring the VS Code Debugger + +To debug the Stencil prerender process, create (or edit) the `launch.json` file with the following configuration: + +```json title="launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "node", + "request": "launch", + "name": "Prerender", + "args": [ + "${workspaceFolder}/node_modules/@stencil/core/bin/stencil", + "prerender", + "${workspaceFolder}/dist/hydrate/index.js", + "--max-workers=0", + "--config=${workspaceFolder}/stencil.config.ts" + ], + "protocol": "inspector" + } + ] +} +``` + +This creates a new debugging configuration using the script that hydrates the app. We're starting up the `stencil prerender` command, and providing it a path to where +the hydrate script can be found. Next we're using `--max-workers=0` so we do not fork numerous processes to each of your CPUs which will make it difficult to debug. diff --git a/versioned_docs/version-v4.18/guides/workers.md b/versioned_docs/version-v4.18/guides/workers.md new file mode 100644 index 000000000..f3e5385cf --- /dev/null +++ b/versioned_docs/version-v4.18/guides/workers.md @@ -0,0 +1,284 @@ +--- +title: Web Workers +sidebar_label: Web Workers +description: Web Workers +slug: /web-workers +--- + +# Web Workers + +[Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) are a widely supported technology (Chrome, Firefox, Safari and Edge) that allows JavaScript to execute in a different thread, maximizing the usage of multiple CPUs; but most importantly not blocking the **main thread**. + +The **main thread** is where JavaScript runs by default and has access to the `document`, `window` and other DOM APIs. The problem is that long-running JS prevents the browser from running smooth animations (CSS animations, transitions, canvas, svg...), making your site look frozen. That's why if your application needs to run CPU-intensive tasks, Web Workers are a great help. + + +## When to use Web Workers? + +The first thing to understand is when to use a Web Workers, and when *not* to use them since they come with a set of costs and limitations: + +- There is no access to the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction). This means you cannot interact with `document`, `window` or any elements in the page. +- There is no access to any of the `@stencil/core` APIs. For example, you cannot declare and use a component in a Web Worker, for the same reasons there is **no access to the DOM**. +- A Web Worker has its own **isolated state** since each worker has their own memory space. For example, a variable declared on the main thread cannot be directly referenced from a worker. +- There is an overhead when passing data between workers and the main thread. As a general rule, it's best to minimize the amount of data sent to and from the worker and be mindful if the work to send your data takes more time than doing it on the main thread. +- Communication is always **asynchronous**. Luckily Promises and async/await makes this relatively easy, but it's important to understand that communication between threads is always asynchronous. +- You can **only** pass [primitives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Primitive_values) and objects that implement the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). Best way to think of it is any data that can be serialized to JSON is safe to use. + +In short, it's generally a good idea to use workers to move logic that is thread-blocking -- or UI-blocking, preventing users from interacting with the page -- into a Web Worker, such as real-time code syntax highlighting. + +## Best Practices when using Web Workers + +- Use pure and functional algorithms in workers. `(input1, input2) => output`. +- The worker logic itself can be as complex as it has to be, however, the input and output data should stay fairly simple. +- Look for ways to reduce passing data between the main thread and worker thread. +- Class instances cannot be passed as data. Instead, only work with data can be JSON serializable. +- Minimize state within the worker, or better yet, completely avoid maintaining any state (e.g., don't put redux inside a worker). +- The cost of a worker should be easily amortized because it would be doing some CPU-intensive jobs. + + +## How vanilla Web Workers "work"? + +The browser comes with a `Worker` API, that works the following way: + +```tsx +const worker = new Worker('/my-worker.js'); +worker.postMessage(['send message to worker']); +worker.onmessage = (ev) => { + console.log('data from worker', ev.data); +}; +``` + +This API, while powerful, is very low level and makes it tedious to write complex apps, since the event-driven paradigm leads easily to [spaghetti-code](https://en.wikipedia.org/wiki/Spaghetti_code), and quickly misses out on strongly-typed functions and data. + +For further information, check out [this fantastic tutorial](https://www.html5rocks.com/en/tutorials/workers/basics/) by our friends at HTML5Rocks. + +A Web Worker also requires the generation of a separate JavaScript bundle, such as the `my-worker.js` file in the example above. This means you usually need extra build scripts and tooling that transpiles and bundles the worker entry point into another `.js` file. Additionally, the main bundle must be able to reference the worker bundle's file location, which is oftentimes a challenge after transpiling, bundling, minifying, filename hashing and deploying to production servers. + +Fortunately, Stencil can help you solve these two problems: + +- Tooling: Transpiling, bundling, hashing, worker url path referencing +- Communication: Converting event-based communication to Promises, while still maintaining types. + +## Web Workers with Stencil + +As we already mention, Stencil's compiler can help you to use workers in production seamlessly. Any TypeScript file within the `src` directory that ends with `.worker.ts` will automatically use a worker. For example: + +**src/stuff.worker.ts:** + +```tsx + +export const sum = async (a: number, b: number) => { + return a + b; +} + +export const expensiveTask = async (buffer: ArrayBuffer) => { + for (let i = 0; i < buffer.length; i++) { + // do a lot of processing + } + return buffer; +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; + +// Import the worker directly. +// Stencil will automatically create +// a proxy and run the module in a worker. +// IDEs and TypeScript will treat this import +// no differently than any other ESM import. +import { sum, expensiveTask } from '../../stuff.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + async componentWillLoad() { + // sum() will run inside a worker! and the result is a Promise + const result = await sum(1, 2); + console.log(result); // 3 + + // expensiveTask() will not block the main thread, + // because it runs in parallel inside the worker. + // Note that the functions must be async. + const newBuffer = await expensiveTask(buffer); + console.log(newBuffer); + } +} +``` + + +Under the hood, Stencil compiles a worker file and uses the standard `new Worker()` API to instantiate the worker. Then it creates proxies for each of the exported functions, so developers can interact with it using [structured programming constructs](https://en.wikipedia.org/wiki/Structured_programming) instead of event-based ones. + +:::note +Workers are already placed in a different chunk, and dynamically loaded using `new Worker()`. You should avoid using a dynamic `import()` to load them, as this will cause two network requests. Instead, use ES module imports as it's only importing the proxies for communicating with the worker. +::: + +### Imports within a worker + +Normal `ESM` imports are possible when building workers in Stencil. Under the hood, the compiler bundles all the dependencies of a worker into a single file that becomes the worker's entry-point, a dependency-free file that can run without problems. + +**src/loader.worker.ts:** + +```tsx +import upngjs from 'upng-js'; +import { Images } from './materials'; + +export const loadTexture = async (imagesSrcs: Images) => { + const images = await Promise.all( + imagesSrcs.map(loadOriginalImage) + ); + return images; +} + +async function loadOriginalImage(src: string) { + const res = await fetch(src); + const png = upngjs.decode(await res.arrayBuffer()); + return png; +} +``` + +In this example, we are building a worker called `loader.worker.ts` that imports an NPM dependency (`upngjs`, used to parse png files), and a local module (`./materials`). Stencil will use [Rollup](https://rollupjs.org/guide/en/) to bundle all dependencies and remove all imports at runtime. Be aware that code will be duplicated if imported inside and outside a worker. + +#### Dynamic imports + +In order to load scripts dynamically inside of a worker, Web Workers come with a handy API, [`importScript()`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts). + +Here's an example of how to use `typescript` directly from a CDN with `importScript()`. + +```tsx +importScripts("https://cdn.jsdelivr.net/npm/typescript@latest/lib/typescript.js"); +``` + +:::note +Do not use `importScript()` to import NPM dependencies you have installed using `npm` or `yarn`. Use normal ES module imports as usual, so the bundler can understand it. +::: + +### Worker Callbacks + +In most cases, waiting for a Promise to resolve with the output data is all we'll need. However, a limitation with native Promises is that it provides only one returned value. Where a traditional callback still shines is that it can be called numerous times with different data. + +Let's say that we have a long running process that may take a few seconds to complete. With a Promise, we're unable to periodically receive the progress of the task, since all we can do is wait for Promise to resolve. + +A feature with Stencil's worker is the ability to pass a callback to the method, and within the worker, execute the callback as much as it's needed before the task resolves. + +In the example below, the task is given a number that it counts down from the number provided, and the task completes when it gets to `0`. During the count down, however, the main thread will still receive an update every second. This example will console log from `5` to `0` + + +**src/countdown.worker.ts:** + +```tsx +export const countDown = (num: number, progress: (p: number) => void) => { + return new Promise(resolve => { + const tmr = setInterval(() => { + num--; + if (num > 0) { + progress(num); + } else { + clearInterval(tmr); + resolve(num); + } + }, 1000); + }); +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; +import { countDown } from '../countdown.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + const startNum = 5; + console.log('start', startNum); + + countDown(startNum, (p) => { + console.log('progress', p); + }).then(result => { + console.log('finish', result); + }); + } +} +``` + +When executed, the result would take 5 seconds and would log: + +``` +start 5 +progress 4 +progress 3 +progress 2 +progress 1 +finish 0 +``` + +## Advanced cases + +Sometimes it might be necessary to access the actual [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) instance, because manual usage of the [`postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage) and [`onmessage`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/onmessage) is desired. However, there's still a tooling challenge in having to bundle the worker, and have the main bundle correctly reference the worker bundle url path. In that case, Stencil also has an API that exposes the worker directly so it can be used instead of the proxies mentioned early. + +For a direct worker reference, add `?worker` at the end of an ESM import. This virtual ES module will export: +- `worker`: The actual Worker instance. +- `workerPath`: The path to the worker's entry-point (usually a path to a `.js` file). +- `workerName`: The name of the worker, useful for debugging purposes. + + +**src/my-app/my-app.tsx:** + +```tsx +import { Component } from '@stencil/core'; +import { sum } from '../../stuff.worker'; + +// Using the ?worker query, allows to access the worker instance directly. +import { worker } from '../../stuff.worker.ts?worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + // Use worker api directly + worker.postMessage(['send data manually']); + + // Use the proxy + const result = await sum(1, 2); + console.log(result); // 3 + } +} +``` + +You can even use this feature you create multiple Worker manually: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; + +const workerPool = [ + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), +]; +``` + +In this example, we exclusively take advantage of the bundling performed by the compiler to obtain the `workerPath` to the worker's entry point, then manually create a pool of workers. + +:::note +Stencil will not instantiate a worker if it's unused, it takes advantage of tree-shaking to do this. +::: + +#### Worker Termination + +Any Web Workers can be terminated using the [`Worker.terminate()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) API, but since Stencil creates one worker shared across all the proxied methods, it's not recommended to terminate it manually. If you have a use-case for using `terminate` and rebuilding workers, then we recommend using the `workerPath` and creating a new Worker directly: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; +const worker = new Worker(workerPath); +// ... +worker.terminate() +``` diff --git a/versioned_docs/version-v4.18/introduction/01-overview.md b/versioned_docs/version-v4.18/introduction/01-overview.md new file mode 100644 index 000000000..a05312401 --- /dev/null +++ b/versioned_docs/version-v4.18/introduction/01-overview.md @@ -0,0 +1,48 @@ +--- +title: Stencil - A Compiler for Web Components +sidebar_label: Overview +description: Stencil has a number of add-ons that you can use with the build process. +slug: /introduction +--- + +# Overview + +## Stencil: A Web Components Compiler + +Stencil is a compiler that generates Web Components (more specifically, Custom Elements). Stencil combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil uses TypeScript, JSX, and CSS to create standards-compliant Web Components that can be used to craft high quality component libraries. + +Web Components generated with Stencil can be used with popular frameworks right +out of the box. In addition, Stencil can generate framework-specific wrappers that +allow Stencil components to be used with a framework-specific developer experience. + +Compared with using the [Custom Elements +APIs](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) +directly, Stencil provides [convenient APIs](../components/api.md) which make writing fast +components simpler. With a Virtual DOM, JSX, and async rendering, it is easy to +create fast and powerful components which are still 100% compatible with Web +Components standards. In addition to making it easier to author Custom +Elements, Stencil also adds a number of key capabilities on top of Web +Components, such as prerendering and objects-as-properties (instead of just +strings). + +The developer experience is also tuned, and comes with live reload and a small dev server baked in to the compiler. + +## How can I use Stencil? + +### Design Systems & Component Libraries + +Stencil's primary objective is providing amazing tools for design systems and component libraries. Components as a concept provide similar language for engineers and designers to have productive conversations about design implementation. [Visit the Stencil for Design Systems page to learn more.](../guides/design-systems.md) + +## The History of Stencil + +Stencil was originally created by the **[Ionic Framework](http://ionicframework.com/)** team in order to build faster, more capable components that worked across every major framework. + +The emergence of Progressive Web Apps as a rapidly growing target for web developers demanded a different approach to web app development performance. With Ionic's classic use of traditional frameworks and bundling techniques, the team was struggling to meet latency and code size demands for Progressive Web Apps that ran equally well on fast and slow networks, across a diversity of platforms and devices. + +Additionally, framework fragmentation had created a web development interoperability nightmare, where components built for one framework didn't work with another framework. + +Web Components offered a solution to both problems, pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + +Web Components by themselves, however, weren't enough. Building fast web apps required innovations that were previously locked up inside of traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. While Stencil is intended to be used primarily to build design systems and component libraries, these innovations allowed entire applications to be built using only Stencil. diff --git a/versioned_docs/version-v4.18/introduction/02-goals-and-objectives.md b/versioned_docs/version-v4.18/introduction/02-goals-and-objectives.md new file mode 100644 index 000000000..7538e2a8b --- /dev/null +++ b/versioned_docs/version-v4.18/introduction/02-goals-and-objectives.md @@ -0,0 +1,31 @@ +--- +title: Stencil Goals and Objectives +sidebar_label: Goals and Objectives +description: Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. +slug: /goals-and-objectives +--- + +# Stencil Goals And Objectives + +Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. It's important to stress that Stencil's goal is to *not* become or be seen as a "framework", but rather our goal is to provide a great developer experience and tooling expected from a framework, while using web-standards within the browser at run-time. In many cases, Stencil can be used as a drop in replacement for traditional frontend frameworks given the capabilities now available in the browser, though using it as such is certainly not required. + +## Web Standards +Components generated by Stencil in the end are built on top of web components, so they work in any major framework or with no framework at all. Additionally, other standards heavily relied on include ES Modules and dynamic imports which have proven to replace traditional bundlers which add unnecessary complexities and run-time JavaScript. By using web-standards, developers can learn and adopt a standard API documented across the world, rather than custom framework APIs that continue to change. + +## Automatic Optimizations +There are countless optimizations and tweaks developers must do to improve performance of components and websites. With a compiler, Stencil is able to analyze component code as an input, and generate optimized components as an output. + +## Future-Friendly +As the world of software development continues to evolve, so too can the compiler. Instead of requiring complete rewrites of components, the compiler can continue to make optimizations using the standard component model as the common input. The compiler allows developers to create future-friendly components, while still staying up-to-date on the latest optimizations without starting over again and again. Additionally, if something changes about any API, the compiler is able to make automatic adjustments and notify the developer exactly what needs to be updated. + +## Run-time Performance +Instead of writing custom client-side JavaScript which every user needs to download and parse for the app to work, Stencil instead prefers to use the already amazing APIs built directly within the browser. These APIs include Custom Elements. + +## Tiny API +Stencil purposely does not come with a large custom API which needs to be learned and re-learned, but rather heavily relies on, you guessed it, web-standards. Again, our goal is to not create yet-another-framework, but rather provide tooling for developers to generate future-friendly components using APIs already baked within the browser. The smaller the API, the easier to learn, and the less that can be broken. + +## Framework Features During Development +If you haven't noticed already we think web-standards are great and offer many benefits. While using web-standards without any structure is certainly possible, and there are actually many use-cases where this would be appropriate, we found that as apps and teams scale it quickly becomes difficult to manage. Developers often gravitate to frameworks because of their great tooling, defined structure, and ability to allow developers to build apps quickly. One of the largest goals of Stencil is to be that intersection of having great framework features and first-class tooling during development but generating future-proof web-standard code, rather than custom framework specific code. + +## Wide Browser Support +For the small minority of browsers that do not support modern browser features and APIs, Stencil will automatically polyfill them on-demand. What this means is that for browsers that already support the feature natively, they will not have to download and parse any unnecessary JavaScript. The great news is that in today's web landscape, most modern APIs are already shipping for what Stencil requires. diff --git a/versioned_docs/version-v4.18/introduction/03-getting-started.md b/versioned_docs/version-v4.18/introduction/03-getting-started.md new file mode 100644 index 000000000..c7a2bb064 --- /dev/null +++ b/versioned_docs/version-v4.18/introduction/03-getting-started.md @@ -0,0 +1,222 @@ +--- +title: Getting Started +sidebar_label: Getting Started +description: Getting Started +slug: /getting-started +--- + +# Getting Started + +## Starting a New Project + +### Prerequisites +Stencil requires a recent LTS version of [NodeJS](https://nodejs.org/) and npm/yarn. +Make sure you've installed and/or updated Node before continuing. + +### Running the `create-stencil` CLI +The `create-stencil` CLI can be used to scaffold a new Stencil project, and can be run using the following command: + +```bash npm2yarn + npm init stencil +``` + +Stencil can be used to create standalone components, or entire apps. +`create-stencil`, will provide a prompt so that you can choose the type of project to start: + +```text +? Select a starter project. + +Starters marked as [community] are developed by the Stencil +Community, rather than Ionic. For more information on the +Stencil Community, please see github.com/stencil-community + +❯ component Collection of web components that can be + used anywhere + app [community] Minimal starter for building a Stencil + app or website + ionic-pwa [community] Ionic PWA starter with tabs layout and routes +``` + +Selecting the 'component' option will prompt you for the name of your project. +Here, we'll name our project 'my-first-stencil-project': + +```bash +✔ Pick a starter › component +? Project name › my-first-stencil-project +``` + +After hitting `ENTER` to confirm your choices, the CLI will scaffold a Stencil project for us in a directory that matches the provided project name. +Upon successfully creating our project, the CLI will print something similar to the following to the console: + +```bash +✔ Project name › my-first-stencil-project +✔ A new git repo was initialized +✔ All setup in 26 ms + + We suggest that you begin by typing: + + $ cd my-first-stencil-project + $ npm install + $ npm start + + $ npm start + Starts the development server. + + $ npm run build + Builds your project in production mode. + + $ npm test + Starts the test runner. + + Further reading: + + - https://github.com/ionic-team/stencil-component-starter + + Happy coding! 🎈 +``` + +The first section describes a few commands required to finish getting your project bootstrapped. + +```bash npm2yarn +cd my-first-stencil-project +npm install +npm start +``` + +This will change your current directory to `my-first-stencil-project`, install your dependencies for you, and start the development server. + +### Useful Initial Commands + +The second section of the `create-stencil` output describes a few useful commands available during the development process: + +- `npm start` starts a local development server. The development server will open a new browser tab containing your +project's components. The dev-server uses hot-module reloading to update your components in the browser as you modify +them for a rapid feedback cycle. + +- `npm run build` creates a production-ready version of your components. The components generated in this step are not +meant to be used in the local development server, but rather within a project that consumes your components. + +- `npm test` runs your project's tests. The `create-stencil` CLI has created both end-to-end and unit tests when scaffolding your project. + +### Source Control + +As of create-stencil v3.3.0, a new git repository will be automatically created for you when you initialize a project if: +1. git is installed +2. Your project is not created under another git work tree (e.g. if you create a new project in a monorepo, a new git repo will not be created) + +Versions of create-stencil prior to v3.3.0 do not interact with any version control systems (VCS). +If you wish to place your project under version control, we recommend initializing your VCS now. +If you wish to use git, run the following after changing your current directory to the root of your Stencil project: + +```bash +$ git init +$ git add -A +$ git commit -m "initialize project using stencil cli" +``` + +## My First Component + +Stencil components are created by adding a new file with a `.tsx` extension, such as `my-component.tsx`. +The `.tsx` extension is required since Stencil components are built using [JSX](../components/templating-and-jsx.md) and TypeScript. + +When we ran `create-stencil` above, it generated a component, `my-component.tsx`, that can be found in the `src/components/my-component` directory: + +```tsx title="my-component.tsx" +import { Component, Prop, h } from '@stencil/core'; +import { format } from '../../utils/utils'; + +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +export class MyComponent { + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; + + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +} +``` + +Once compiled, this component can be used in HTML just like any other tag. + +```markup + +``` + +When rendered, the browser will display `Hello World! I'm Stencil 'Don't call me a framework' JS`. + +### Anatomy of `my-component` + +Let's dive in and describe what's happening in `my-component`, line-by-line. + +After the import statements, the first piece we see is the [`@Component` decorator](../components/component.md): +```tsx +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +``` +This decorator provides metadata about our component to the Stencil compiler. +Information, such as the custom element name (`tag`) to use, can be set here. +This decorator tells Stencil to: +- Set the [element's name](../components/component.md#tag) to 'my-component' +- [Apply the stylesheet](../components/component.md#styleurl) 'my-component.css' to the component +- Enable [native Shadow DOM functionality](../components/component.md#shadow) for this component + +Below the `@Component()` decorator, we have a standard JavaScript class declaration: + +```tsx +export class MyComponent { +``` + +Within this class is where you'll write the bulk of your code to bring your Stencil component to life. + +Next, the component contains three class members, `first`, `middle` and `last`. +Each of these class members have the [`@Prop()` decorator](../components/properties.md#the-prop-decorator-prop) applied to them: +```ts + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; +``` +`@Prop()` tells Stencil that the property is public to the component, and allows Stencil to rerender when any of these public properties change. +We'll see how this works after discussing the `render()` function. + +In order for the component to render something to the screen, we must declare a [`render()` function](../components/templating-and-jsx.md#basics) that returns JSX. +If you're not sure what JSX is, be sure to reference the [Using JSX](../components/templating-and-jsx.md) docs. + +The quick idea is that our render function needs to return a representation of the HTML we want to push to the DOM. + +```tsx + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +``` + +This component's `render()` returns a `
    ` element, containing text to render to the screen. + +The `render()` function uses all three class members decorated with `@Prop()`, through the `getText` function. +Declaring private functions like `getText` helps pull logic out of the `render()` function's JSX. + +Any property decorated with `@Prop()` is also automatically watched for changes. +If a user of our component were to change the element's `first`, `middle`, or `last` properties, our component would fire its `render()` function again, updating the displayed content. + +## Updating Stencil + +To get the latest version of @stencil/core you can run: + +```bash npm2yarn +npm install @stencil/core@latest --save-exact +``` diff --git a/versioned_docs/version-v4.18/introduction/_category_.json b/versioned_docs/version-v4.18/introduction/_category_.json new file mode 100644 index 000000000..fa1c06ac8 --- /dev/null +++ b/versioned_docs/version-v4.18/introduction/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Introduction", + "position": 1 +} diff --git a/versioned_docs/version-v4.18/introduction/upgrading-to-stencil-four.md b/versioned_docs/version-v4.18/introduction/upgrading-to-stencil-four.md new file mode 100644 index 000000000..56b492853 --- /dev/null +++ b/versioned_docs/version-v4.18/introduction/upgrading-to-stencil-four.md @@ -0,0 +1,257 @@ +--- +title: Upgrading to Stencil v4.0.0 +description: Upgrading to Stencil v4.0.0 +url: /docs/upgrading-to-stencil-4 +--- + +# Upgrading to Stencil v4.0.0 + +## Getting Started + +We recommend that you only upgrade to Stencil v4 from Stencil v3. +If you're a few versions behind, we recommend upgrading one major version at a time (from v1 to v2, then v2 to v3, finally v3 to v4). +This will minimize the number of breaking changes you have to deal with at the same time. + +For breaking changes introduced in previous major versions of the library, see: +- [Stencil v3 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v300) +- [Stencil v2 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-two) +- [Stencil v1 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-one) + +For projects that are on Stencil v3, install the latest version of Stencil v4: `npm install @stencil/core@4` + + +## Updating Your Code + +### New Configuration Defaults +Starting with Stencil v4.0.0, the default configuration values have changed for a few configuration options. +The following sections lay out the configuration options that have changed, their new default values, and ways to opt-out of the new behavior (if applicable). + +#### `transformAliasedImportPaths` + +TypeScript projects have the ability to specify a path aliases via the [`paths` configuration in their `tsconfig.json`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) like so: +```json title="tsconfig.json" +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@utils": ["src/utils/index.ts"] + } + } +} +``` +In the example above, `"@utils"` would be mapped to the string `"src/utils/index.ts"` when TypeScript performs type resolution. +The TypeScript compiler does not however, transform these paths from their keys to their values as a part of its output. +Instead, it relies on a bundler/loader to do the transformation. + +The ability to transform path aliases was introduced in [Stencil v3.1.0](https://github.com/ionic-team/stencil/releases/tag/v3.1.0) as an opt-in feature. +Previously, users had to explicitly enable this functionality in their `stencil.config.ts` file with `transformAliasedImportPaths`: +```ts title="stencil.config.ts - enabling 'transformAliasedImportPaths' in Stencil v3.1.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: true, + // ... +}; +``` + +Starting with Stencil v4.0.0, this feature is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v3.1.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPaths' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: false, + // ... +}; +``` + +For more information on this flag, please see the [configuration documentation](../config/01-overview.md#transformaliasedimportpaths) + +#### `transformAliasedImportPathsInCollection` + +Introduced in [Stencil v2.18.0](https://github.com/ionic-team/stencil/releases/tag/v2.18.0), `transformAliasedImportPathsInCollection` is a configuration flag on the [`dist` output target](../output-targets/dist.md#transformaliasedimportpathsincollection). +`transformAliasedImportPathsInCollection` transforms import paths, similar to [`transformAliasedImportPaths`](#transformaliasedimportpaths). +This flag however, only enables the functionality of `transformAliasedImportPaths` for collection output targets. + +Starting with Stencil v4.0.0, this flag is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v2.18.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPathsInCollection' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist', + transformAliasedImportPathsInCollection: false, + }, + // ... + ] + // ... +}; +``` + +For more information on this flag, please see the [`dist` output target's documentation](../output-targets/dist.md#transformaliasedimportpathsincollection). + +### In Browser Compilation Support Removed + +Prior to Stencil v4.0.0, components could be compiled from TSX to JS in the browser. +This feature was seldom used, and has been removed from Stencil. +At this time, there is no replacement functionality. +For additional details, please see the [request-for-comment](https://github.com/ionic-team/stencil/discussions/4134) on the Stencil GitHub Discussions page. + +### Legacy Context and Connect APIs Removed + +Previously, Stencil supported `context` and `connect` as options within the `@Prop` decorator. +Both of these APIs were deprecated in Stencil v1 and are now removed. + +```ts +@Prop({ context: 'config' }) config: Config; +@Prop({ connect: 'ion-menu-controller' }) lazyMenuCtrl: Lazy; +``` +To migrate away from usages of `context`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propcontext). +To migrate away from usages of `connect`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propconnect). + +### Legacy Browser Support Removed + +In Stencil v3.0.0, we announced [the deprecation of IE 11, pre-Chromium Edge, and Safari 10 support](https://github.com/ionic-team/stencil/blob/1a8ff39073a88d1372beaa98434dbe2247f68a85/BREAKING_CHANGES.md?plain=1#L78). +In Stencil v4.0.0, support for these browsers has been dropped (for a full list of supported browsers, please see our [Browser Support policy](../reference/support-policy.md#browser-support)). + +By dropping these browsers, a few configuration options are no longer valid in a Stencil configuration file: + +#### `__deprecated__cssVarsShim` + +The `extras.__deprecated__cssVarsShim` option caused Stencil to include a polyfill for [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/--*). +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__dynamicImportShim` + +The `extras.__deprecated__dynamicImportShim` option caused Stencil to include a polyfill for +the [dynamic `import()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) +for use at runtime. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__safari10` + +The `extras.__deprecated__safari10` option would patch ES module support for Safari 10. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__shadowDomShim` + +The `extras.__deprecated__shadowDomShim` option would check whether a shim for [shadow +DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) +was needed in the current browser, and include one if so. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Legacy Cache Stats Config Flag Removed + +The `enableCacheStats` flag was used in legacy behavior for caching, but has not been used for some time. This +flag has been removed from Stencil's API and should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Drop Node 14 Support + +Stencil no longer supports Node 14. +Please upgrade local development machines, continuous integration pipelines, etc. to use Node v16 or higher. +For the full list of supported runtimes, please see [our Support Policy](../reference/support-policy.md#javascript-runtime). + +## Information Included in `docs-json` Expanded + +For Stencil v4 the information included in the output of the `docs-json` output +target was expanded to include more information about the types of properties +and methods on Stencil components. + +For more context on this change, see the [documentation for the new `supplementalPublicTypes`](../documentation-generation/docs-json.md#supplementalpublictypes) +option for the JSON documentation output target. + +### `JsonDocsEvent` + +The JSON-formatted documentation for an `@Event` now includes a field called +`complexType` which includes more information about the types referenced in the +type declarations for that property. + +Here's an example of what this looks like for the [ionBreakpointDidChange +event](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/modal/modal.tsx#L289-L292) +on the `Modal` component in Ionic Framework: + +```json +{ + "complexType": { + "original": "ModalBreakpointChangeEventDetail", + "resolved": "ModalBreakpointChangeEventDetail", + "references": { + "ModalBreakpointChangeEventDetail": { + "location": "import", + "path": "./modal-interface", + "id": "src/components/modal/modal.tsx::ModalBreakpointChangeEventDetail" + } + } + } +} +``` + +### `JsonDocsMethod` + +The JSON-formatted documentation for a `@Method` now includes a field called +`complexType` which includes more information about the types referenced in +the type declarations for that property. + +Here's an example of what this looks like for the [open +method](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/select/select.tsx#L261-L313) +on the `Select` component in Ionic Framework: + +```json +{ + "complexType": { + "signature": "(event?: UIEvent) => Promise", + "parameters": [ + { + "tags": [ + { + "name": "param", + "text": "event The user interface event that called the open." + } + ], + "text": "The user interface event that called the open." + } + ], + "references": { + "Promise": { + "location": "global", + "id": "global::Promise" + }, + "UIEvent": { + "location": "global", + "id": "global::UIEvent" + }, + "HTMLElement": { + "location": "global", + "id": "global::HTMLElement" + } + }, + "return": "Promise" + } +} +``` + +## Additional Packages + +To ensure the proper functioning of other `@stencil/` packages, it is advisable for projects utilizing any of the packages mentioned below to upgrade to the minimum package version specified. + +| Package | Minimum Package Version | GitHub | Documentation | +|----------------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|-------------------------------------------------------------| +| `@stencil/angular-output-target` | [0.7.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fangular-output-target%400.7.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/angular.md) | +| `@stencil/sass` | [3.0.4](https://github.com/ionic-team/stencil-sass/releases/tag/v3.0.4) | [GitHub](https://github.com/ionic-team/stencil-sass) | [GitHub README](https://github.com/ionic-team/stencil-sass) | +| `@stencil/store` | [2.0.8](https://github.com/ionic-team/stencil-store/releases/tag/v2.0.8) | [GitHub](https://github.com/ionic-team/stencil-store) | [Stencil Doc Site](../guides/store.md) | +| `@stencil/react-output-target` | [0.5.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Freact-output-target%400.5.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/react.md) | +| `@stencil/vue-output-target` | [0.8.6](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fvue-output-target%400.8.6) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/vue.md) | + +## Need Help Upgrading? + +Be sure to look at the Stencil [v4.0.0 Breaking Changes Guide](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v400). + +If you need help upgrading, please post a thread on the [Stencil Discord](https://chat.stenciljs.com). diff --git a/versioned_docs/version-v4.18/output-targets/01-overview.md b/versioned_docs/version-v4.18/output-targets/01-overview.md new file mode 100644 index 000000000..550880879 --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/01-overview.md @@ -0,0 +1,68 @@ +--- +title: Stencil Output Targets +sidebar_label: Overview +description: Stencil Output Targets +slug: /output-targets +--- + +# Output Targets + +One of the more powerful features of the compiler is its ability to generate various builds depending on _"how"_ the components are going to be used. Stencil is able to take an app's source and compile it to numerous targets, such as a webapp to be deployed on an http server, as a third-party component lazy-loaded library to be distributed on [npm](https://www.npmjs.com/), or a vanilla custom elements bundle. By default, Stencil apps have an output target type of `www`, which is best suited for a webapp. + + +## Output Target Types: + - [`dist`: Distribution](./dist.md) + - [`www`: Website](./www.md) + - [`dist-custom-elements`: Custom Elements](./custom-elements.md) + +## Example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist' + }, + { + type: 'www' + } + ] +}; +``` + +## Primary Package Output Target Validation + +If `validatePrimaryPackageOutputTarget: true` is set in your project's [Stencil config](../config/01-overview.md#validateprimarypackageoutputtarget) Stencil will +attempt to validate certain fields in your `package.json` that correspond with the generated distribution code. Because Stencil can output many different formats +from a single project, it can only validate that the `package.json` has field values that align with one of the specified output targets in your project's config. +So, Stencil allows you to designate which output target should be used for this validation and thus which will be the default distribution when bundling your +project. + +This behavior only affects a small subset of output targets so a flag exists on the following targets that are eligible for this level of validation: `dist`, `dist-types`, +`dist-collection`, and `dist-custom-elements`. For any of these output targets, you can configure the target to be validated as follows: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + outputTargets: [ + { + type: 'dist', + // This flag is what tells Stencil to use this target for validation + isPrimaryPackageOutputTarget: true, + ... + }, + ... + ], + // If this is not set, Stencil will not validate any targets + validatePrimaryPackageOutputTarget: true, +}; +``` + +:::note +Stencil can only validate one of these output targets for your build. If multiple output targets are marked for validation, Stencil will use +the first designated target in the array and ignore all others. +::: diff --git a/versioned_docs/version-v4.18/output-targets/_category_.json b/versioned_docs/version-v4.18/output-targets/_category_.json new file mode 100644 index 000000000..ae7d15137 --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Output Targets", + "position": 6 +} diff --git a/versioned_docs/version-v4.18/output-targets/copy-tasks.md b/versioned_docs/version-v4.18/output-targets/copy-tasks.md new file mode 100644 index 000000000..1e2d5eaa5 --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/copy-tasks.md @@ -0,0 +1,152 @@ +--- +title: Stencil Copy Tasks +sidebar_label: Copy Tasks +description: Stencil Copy Tasks +slug: /copy-tasks +--- + + +# Copy Tasks for Output Targets + +All of Stencil's non-documentation output targets +([`dist-custom-elements`](./custom-elements.md), [`dist`](./dist.md), and +[`www`](./www.md)) support a `copy` config which allows you to define file copy +operations which Stencil will automatically perform as part of the build. This +could be useful if, for instance, you had some static assets like images which +should be distributed alongside your components. + +The `copy` attribute on these output targets expects an array of objects corresponding to the following `CopyTask` interface: + +```ts reference title="CopyTask" +https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 +``` + +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + +## Examples + +### Images in the `www` Output Target + +The `copy` config within the following [`www` output target](./www.md) config +will cause Stencil to copy the entire directory from `src/images` to +`www/images`: + +```tsx + outputTargets: [ + { + type: 'www', + copy: [ + { src: 'images' } + ] + } + ] +``` + +In this example, since the `srcDir` property is not set, the default source +directory is `src/`, and since `dest` is not set the contents of `src/images` +will be copied to a new `images` directory in `www`, the default destination +directory for the `www` Output Target. + + +### Setting the `dest` option + +The `dest` property can also be optionally set on a `CopyTask` to either an +absolute path or a path relative to the build directory of the output target. + +In this example we've customized the build directory to be `public` instead of +the default (`'www'`), which, in combination with `dest: 'static/web-fonts'` +will copy the contents of `src/files/fonts` over to `public/static/web-fonts`: + +```tsx + outputTargets: [ + { + type: 'www', + dir: 'public', + copy: [ + { src: 'files/fonts', dest: 'static/web-fonts' } + ] + } + ] +``` + +:::note +When `dest` is set on a `CopyTask` Stencil will, by default, copy all the contents +of the `src` directory to the `dest` directory without creating a new +subdirectory for the contents of `src`. The `keepDirStructure` option can +control this behavior. If it's set to `true` Stencil will always create a +new subdirectory within `dest` with the same name as the `src` directory. In the +above example this would result in the contents of `src/files/fonts` being copied +to `public/static/web-fonts/fonts` instead of `public/static/web-fonts`. + +See the above documentation for the `keepDirStructure` option for more details. +::: + +### Opting-in to warnings + +By default, Stencil will not log a warning if a file or directory specified in +`src` cannot be located. To opt-in to warnings if a copy task source cannot be +found, set `warn: true` in the `CopyTask` object, like so: + +```tsx + outputTargets: [ + { + type: 'dist', + copy: [ + { src: 'fonts', warn: true } + ] + } + ] +``` diff --git a/versioned_docs/version-v4.18/output-targets/custom-elements.md b/versioned_docs/version-v4.18/output-targets/custom-elements.md new file mode 100644 index 000000000..b6fed7bbe --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/custom-elements.md @@ -0,0 +1,236 @@ +--- +title: Custom Elements with Stencil +sidebar_label: dist-custom-elements +description: Custom Elements with Stencil +slug: /custom-elements +--- + +# Custom Elements + +The `dist-custom-elements` output target creates custom elements that directly extend `HTMLElement` and provides simple utility functions for easily defining these elements on the [Custom Element Registry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry). This output target excels in use in frontend frameworks and projects that will handle bundling, lazy-loading, and custom element registration themselves. + +This target can be used outside of frameworks as well, if lazy-loading functionality is not required or desired. For using lazily loaded Stencil components, please refer to the [dist output target](./dist.md). + +To generate components using the `dist-custom-elements` output target, add it to a project's `stencil.config.ts` file like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + // Other top-level config options here + outputTargets: [ + { + type: 'dist-custom-elements', + // Output target config options here + }, + // Other output targets here + ], +}; +``` + +## Config + +### copy + +_default: `undefined`_ + +An array of [copy tasks](./copy-tasks.md) to be executed during the build process. + +### customElementsExportBehavior + +_default: `'default'`_ + +By default, the `dist-custom-elements` output target generates a single file per component, and exports each of those files individually. + +In some cases, library authors may want to change this behavior, for instance to automatically define component children, provide a single file containing all component exports, etc. + +This config option provides additional behaviors that will alter the default component export _OR_ custom element definition behaviors +for this target. The desired behavior can be set via the following in a project's Stencil config: + +```ts +// stencil.config.ts +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + customElementsExportBehavior: 'default' | 'auto-define-custom-elements' | 'bundle' | 'single-export-module', + }, + // ... + ], + // ... +}; +``` + +| Option | Description | +| ----------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `default` | No additional re-export or auto-definition behavior will be performed.

    This value will be used if no explicit value is set in the config, or if a given value is not a valid option. | +| `auto-define-custom-elements` | A component and its children will be automatically defined with the `CustomElementRegistry` when the component's module is imported. | +| `bundle` | A utility `defineCustomElements()` function is exported from the `index.js` file of the output directory. This function can be used to quickly define all Stencil components in a project on the custom elements registry. | +| `single-export-module` | All component and custom element definition helper functions will be exported from the `index.js` file in the output directory. This file can be used as the root module when distributing your component library, see [Publishing](/publishing) for more details. | + +:::note +At this time, components that do not use JSX cannot be automatically +defined. This is a known limitation of Stencil that users should be aware of. +::: + +### dir + +_default: `'dist/components'`_ + +This config option allows you to change the output directory where the compiled output for this output target will be written. + +### empty + +_default: `true`_ + +Setting this flag to `true` will remove the contents of the [output directory](#dir) between builds. + +### externalRuntime + +_default: `true`_ + +Setting this flag to `true` results in the following behaviors: + +1. Minification will follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). +2. Filenames will not be hashed. +3. All imports from packages under `@stencil/core/*` will be marked as external and therefore not included in the generated Rollup bundle. + +Ensure that `@stencil/core` is included in your list of dependencies if you set this option to `true`. This is crucial to prevent any runtime errors. + +### generateTypeDeclarations + +_default: `true`_ + +By default, Stencil will generate type declaration files (`.d.ts` files) as a part of the `dist-custom-elements` output target through the `generateTypeDeclarations` field on the target options. Type declaration files will be placed in the `dist/types` directory in the root of a Stencil project. At this time, this output destination is not able to be configured. + +Setting this flag to `false` will not generate type declaration files for the `dist-custom-elements` output target. + +:::note +When set to generate type declarations, Stencil respects the export behavior selected via `customElementsExportBehavior` and generates type declarations specific to the content of the generated [output directory's](#dir) `index.js` file. +::: + +### includeGlobalScripts + +_default: `false`_ + +Setting this flag to `true` will include [global scripts](../config/01-overview.md#globalscript) in the bundle and execute them once the bundle entry point in loaded. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### minify + +_default: `false`_ + +Setting this flag to `true` will cause file minification to follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). _However_, if [`externalRuntime`](#externalruntime) is enabled, it will override this option and always result in minification being disabled. + +## Making Assets Available + +For performance reasons, the generated bundle does not include [local assets](../guides/assets.md) built within the JavaScript output, +but instead it's recommended to keep static assets as external files. By keeping them external this ensures they can be requested on-demand, rather +than either welding their content into the JS file, or adding many URLs for the bundler to add to the output. +One method to ensure [assets](../guides/assets.md) are available to external builds and http servers is to set the asset path using `setAssetPath()`. + +The `setAssetPath()` function is used to manually set the base path where static assets can be found. +For the lazy-loaded output target the asset path is automatically set and assets copied to the correct +build directory. However, for custom elements builds, the `setAssetPath(path)` should be +used to customize the asset path depending on where they are found on the http server. + +If the component's script is a `type="module"`, it's recommended to use `import.meta.url`, such +as `setAssetPath(import.meta.url)`. Other options include `setAssetPath(document.currentScript.src)`, or using a bundler's replace plugin to +dynamically set the path at build time, such as `setAssetPath(process.env.ASSET_PATH)`. + +```tsx +import { setAssetPath } from 'my-library/dist/components'; + +setAssetPath(document.currentScript.src); +``` + +Make sure to copy the assets over to a public directory in your app. This configuration depends on how your script is bundled, or lack of +bundling, and where your assets can be loaded from. How the files are copied to the production build directory depends on the bundler or tooling. +The configs below provide examples of how to do this automatically with popular bundlers. + +## Example Bundler Configs + +Instructions for consuming the custom elements bundle vary depending on the bundler you're using. These examples will help your users consume your components with webpack and Rollup. + +The following examples assume your component library is published to NPM as `my-library`. You should change this to the name you actually publish your library with. + +Users will need to install your library before importing them. + +```bash npm2yarn +npm install my-library +``` + +### webpack.config.js + +A webpack config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `CopyPlugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); + +module.exports = { + entry: './src/index.js', + output: { + filename: 'main.js', + path: path.resolve(__dirname, 'dist'), + }, + module: { + rules: [ + { + test: /\.css$/i, + use: ['style-loader', 'css-loader'], + }, + ], + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + to: path.resolve(__dirname, 'dist/assets'), + }, + ], + }), + ], +}; +``` + +### rollup.config.js + +A Rollup config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `rollup-copy-plugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +import path from 'path'; +import commonjs from '@rollup/plugin-commonjs'; +import copy from 'rollup-plugin-copy'; +import postcss from 'rollup-plugin-postcss'; +import resolve from '@rollup/plugin-node-resolve'; + +export default { + input: 'src/index.js', + output: [{ dir: path.resolve('dist/'), format: 'es' }], + plugins: [ + resolve(), + commonjs(), + postcss({ + extensions: ['.css'], + }), + copy({ + targets: [ + { + src: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + dest: path.resolve(__dirname, 'dist'), + }, + ], + }), + ], +}; +``` diff --git a/versioned_docs/version-v4.18/output-targets/dist.md b/versioned_docs/version-v4.18/output-targets/dist.md new file mode 100644 index 000000000..5c33af5d2 --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/dist.md @@ -0,0 +1,106 @@ +--- +title: Distributing Web Components Built with Stencil +sidebar_label: dist +description: Distributing Web Components Built with Stencil +slug: /distribution +--- + +# Distribution Output Target + +The `dist` type is to generate the component(s) as a reusable library that can be self-lazy loading, such as [Ionic](https://www.npmjs.com/package/@ionic/core). When creating a distribution, the project's `package.json` will also have to be updated. However, the generated bundle is tree-shakable, ensuring that only imported components will end up in the build. + +```tsx +outputTargets: [ + { + type: 'dist' + } +] +``` + +## Config + +### collectionDir + +The `collectionDir` config specifies the output directory within the [distribution directory](#dir) where the transpiled output of Stencil components will be written. + +This option defaults to `collection` when omitted from a Stencil configuration file. + +### dir + +The `dir` config specifies the public distribution directory. This directory is commonly the `dist` directory found within [npm packages](https://docs.npmjs.com/getting-started/packages). This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended that this directory not be committed to a repository. + +This option defaults to `dist` when omitted from a Stencil configuration file. + +### empty + +By default, before each build the `dir` directory will be emptied of all files. To prevent this directory from being emptied, change this value to `false`. + +This flag defaults to `true` when omitted from a Stencil configuration file. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### transformAliasedImportPathsInCollection + +*default: `true`* + +This option will allow [path aliases](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in a project's `tsconfig.json` to be transformed into relative paths in the code output under the [collectionDir](#collectiondir) subdirectory for this output target. This does not affect imports for external packages. + +An example of path transformation could look something like: + +```ts +// Source code +import * as utils from '@utils'; + +// Output code +import * as utils from '../path/to/utils'; +``` + +:::tip +If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config. +::: + +### esmLoaderPath + +*default: `/dist/loader`* + +Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading. Read more about the loader directory in the [section below](#loader). + +If you don't use a custom [exports](https://nodejs.org/api/packages.html#exports) map, users would have to import the loader script via: + +```js +import { defineCustomElements } from 'stencil-library/dist/loader' +``` + +By setting `esmLoaderPath` to e.g. `../loader` you can shorten or rename the import path to: + +```js +import { defineCustomElements } from 'stencil-library/loader' +``` + +## Publishing + +Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md). + +## Loader + +The `dist` output target generates a loader directory that exports `setNonce`, `applyPolyfills` and `defineCustomElements` helper functions when imported within an ESM context. This allows you to register all components of your library to be used in your project in an application setup script, e.g.: + +```ts +import { applyPolyfills, defineCustomElements, setNonce } from 'stencil-library/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +applyPolyfills().then(() => { + defineCustomElements(); +}); +``` + +This is an alternative approach to e.g. loading the components directly through a script tag as mentioned below. Read more about `setNonce` and when to set it in our guide on [Content Security Policy Nonces](../guides/csp-nonce.md). diff --git a/versioned_docs/version-v4.18/output-targets/www.md b/versioned_docs/version-v4.18/output-targets/www.md new file mode 100644 index 000000000..6c3079364 --- /dev/null +++ b/versioned_docs/version-v4.18/output-targets/www.md @@ -0,0 +1,32 @@ +--- +title: Webapp Output Target +sidebar_label: www +description: Webapp Output Target +slug: /www +--- + +# Webapp Output Target: `www` + +The `www` output target type is oriented for webapps and websites, hosted from an http server, which can benefit from prerendering and service workers, such as this very site you're reading. If the `outputTarget` config is not provided it'll default to having just the `www` type. + +Even if a project is meant to only build a reusable component library, the `www` output target is useful to build out and test the components throughout development. + +```tsx +outputTargets: [ + { + type: 'www' + } +] +``` + +## Config + +| Property | Description | Default | +|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| +| `baseUrl` | The `baseUrl` represents the site's "base" url to be served from. For example, this site's base url is `https://stenciljs.com/`. However, if the entire site's output is to live within a sub directory, then this directory's path should be the `baseUrl`. For example, Ionic's documentation is a stand-alone Stencil site that lives in the `/docs` directory within `https://ionicframework.com/`. In this example, `https://ionicframework.com/docs/` would be the base url. | `/` | +| `buildDir` | The `buildDir` is the directory of Stencil's generated scripts, such as the component files. For production builds, this directory will contain both `es5` and `esm` builds for each component. (Don't worry, users only request the one their browser needs.) | `build` | +| `dir` | The `dir` config specifies the public web distribution directory. This directory is commonly the root directory of an app to be served, such as serving static files from. This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended this directory is not committed to a repository. | `www` | +| `empty` | By default, before each build the `dir` directory will be emptied of all files. However, to prevent this directory from being emptied change this value to `false`. | `true` | +| `indexHtml` | The `indexHtml` property represents the location of the root index html file. | `index.html` | +| `serviceWorker` | The `serviceWorker` config lets you customize the service worker that gets automatically generated by the Stencil compiler. To override Stencil's defaults, set any of the values listed in the [Workbox documentation](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). + diff --git a/versioned_docs/version-v4.18/reference/_category_.json b/versioned_docs/version-v4.18/reference/_category_.json new file mode 100644 index 000000000..75879876e --- /dev/null +++ b/versioned_docs/version-v4.18/reference/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Reference", + "position": 10 +} diff --git a/versioned_docs/version-v4.18/reference/faq.md b/versioned_docs/version-v4.18/reference/faq.md new file mode 100644 index 000000000..eab0321a9 --- /dev/null +++ b/versioned_docs/version-v4.18/reference/faq.md @@ -0,0 +1,192 @@ +--- +title: Stencil Frequently Asked Questions +sidebar_label: FAQ +description: Stencil is a developer-focused toolchain for building reusable, scalable component libraries. +slug: /faq +--- + +# FAQ + +## Introduction + +### What is Stencil? + +Stencil is a developer-focused toolchain for building reusable, scalable component libraries. It provides a compiler that generates highly optimized Web Components, and combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil focuses on building components with web standards. It’s used by developers and organizations around the world, and is [100% free and MIT open source](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### What does Stencil do? + +Stencil helps developers and teams build and share custom components. Since Stencil generates standards-compliant Web Components, the components you build with Stencil will work with many popular frameworks right out of the box, and can even be used without a framework because they are just Web Components. Stencil also enables a number of key capabilities on top of Web Components, in particular, prerendering, and objects-as-properties (instead of just strings). + + +### Who is Stencil for? + +Stencil is for developers and teams that want to build custom component libraries that can be shared across teams, frameworks and large organizations. + +Stencil can also be used by designers who want their original design visions delivered consistently, with high fidelity, to all users. + + +### Who makes Stencil? + +Stencil is an open source project started by the [Ionic core team](https://ionicframework.com/), with contributions also coming from the community. + + +### Why was Stencil created? + +Stencil was created by the Ionic Framework team to make our own component library faster, smaller, and compatible with all major frameworks. Web Components offered a solution by pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + + +### Who uses Stencil? + +Stencil was initially developed for Ionic Framework which is a very successful Web Component-based library & UI framework. Web Components are now in thousands of app store apps, and nearly 4 million new Ionic Framework projects are being created every year. + + +### How does Stencil compare to traditional frameworks? + +The Web Component ecosystem has a diverse set of players, each with a different long-term vision for what Web Components can and should do. + +Some think Web Components should replace third-party app frameworks, while others think that Web Components are more suited for leaf/style/design nodes and shouldn’t get in the business of your app’s component system. There are also many framework developers that don’t see the point of Web Components, or consider them to be an affront to front-end innovation. + +With Stencil, our vision is somewhere in the middle. In the long term, we see app development teams continuing to use their framework of choice. We envision these frameworks continuing to get better, smaller, and more efficient, with increasingly good support for targeting and consuming Web Components -- and big teams will be consuming an increasing amount of Web Components as companies continue to embrace them for shared component libraries. + +At the same time, we believe an indispensable feature for Web Components is solving those component distribution and design system problems. We also believe, however, that 90% of the market doesn’t have those problems to begin with, so the current debate about the merits of Web Components is somewhat unproductive. + + +### Why is Stencil considered framework-agnostic? + +Perhaps the most appealing benefit of Web Components is that they give your development teams the flexibility to choose the underlying tools and frameworks - and versions of those frameworks - and tools that they prefer. As pointed out earlier, one of the great challenges of implementing a universal set of components is getting all of your development teams to standardize on just one set of technologies. With Web Components, each team can use what works best for them, giving them complete freedom to use the tools they love—today and tomorrow. + + +## What does Stencil provide? + +### Does Stencil have a component library? + +The most widely used Stencil component library is the Ionic Framework, however, Stencil itself is only a toolchain and does not provide its own component library. We encourage you to first review Ionic components if you are building an application. + + +### Is Stencil a framework? + +Stencil purposely does not strive to act as a stand-alone framework, but rather a tool which allows developers to scale framework-agnostic components across many projects, teams and large organizations. One of Stencil’s superpowers is its flexibility: its components could be used stand-alone, or within traditional frameworks. + + +### Does Stencil come with a testing framework? + +Yes, Stencil provides a rich set of APIs for unit and End-to-end tests. [Learn more about testing with Stencil](../testing/01-overview.md). + + + +## Technology + + +### Why does Stencil use web components? + +By using a consistent set of web standards, Web Components do not depend on a specific framework runtime to execute. As frameworks change their APIs, Web Components do not, allowing for the original source to continue to work natively in a browser. + + +### How is Stencil able to optimize component file size and startup? + +Traditional frameworks provide a runtime API, and developers can pick and choose which APIs to use per component. However, this means every feature needs to be available to every component, just in case the component may or may not use the API. + +With Stencil, the compiler is able to perform static analysis on each component in order to understand which APIs are and are not being used. By doing so, Stencil is able to customize each build to use exactly what each component needs, making for a highly optimized runtime with minimal size. + +Since Stencil uses a compiler, it is able to adjust code as new improvements and features become available. Source code can continue to be written using the same public API and syntax, while the compiler can adjust the code to further take advantage of modern features, without requiring re-writes. + + +### What template syntax does Stencil use? + +Stencil uses [JSX](https://react.dev/learn/writing-markup-with-jsx), a markup language popularized by the React library. + + +### Can Stencil components be lazy loaded? + +Yes! Lazy loading components helps to reduce application startup times, decrease bundle sizes, and improve distribution. + +Because users are able to dynamically load only what is used, startup times are drastically reduced and users only load exactly what their application’s first paint requires. + +At the same time, components built with Stencil can still be imported and consumed by traditional bundlers. + + +### Why are Stencil components written with TypeScript? + +Stencil was originally built for Ionic, and in our experience we’ve found TypeScript to be a valuable tool for maintaining a large codebase across multiple teams. + + +### What dependencies does the Stencil runtime have? + +None. The code generated by Stencil does not rely on Stencil, but rather it generates highly-optimized, framework-free, stand-alone code which runs natively in the browser. + + +### Can data be passed to Web Components? + +Just like any other DOM element in a webpage, any data in the form of arrays, objects, strings and numbers can be passed to element properties. Stencil is designed from the ground up to ensure this capability stays unlocked for application developers. + + +### What technology is Stencil built with? + +The Stencil compiler is built with TypeScript and is [distributed on npm](https://www.npmjs.com/package/@stencil/core). Its distribution includes types, making it easier for developers to use Stencil APIs. + + +## Capabilities + +### Where can Stencil components be used? + +One great advantage of using Web Components is that your component library will work across all projects, not just desktop web apps. + +For example, using a hybrid mobile framework like Ionic, you can deploy Web Components across just about any platform or device, from native iOS and Android apps, to Electron and desktop web apps, and even Progressive Web Apps. + + +### What are the limitations of Web Components? + +The [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) specs are purposely low-level, and on their own, they do not provide a framework quality developer experience. Web Components run on a fairly primitive set of standards, so you will need a little help to get them to meet your objectives. + +Some limitations include: + +When you try to use pure vanilla Web Components in an application, functionality like server-side rendering and progressive enhancement is not supported by default, and +some out-of-date clients don’t support the Web Components standard. + +In addition, while Web Components technically work with any framework, there are some limitations like lack of type support and input bindings, and challenges passing properties to components, as noted above. + +The good news is that, with help from open source tools like Stencil, you can overcome all of these challenges. Stencil includes framework bindings for Angular, React, and Vue, so you can easily import Web Component libraries into any framework, and interact with them just like they were native to that framework, with all the functionality you’re used to. + + +### What are framework bindings? + +While Web Components can be paired with any JavaScript framework, Stencil has built-in special-purpose bindings to deliver the more advanced features enterprise teams expect when building applications in Angular, React, and Vue. + + +### What features does Stencil add to Web Components? + +Web Components by themselves weren't enough to provide a quality development experience. Building fast web apps required innovations that were previously locked up inside traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. + +Compared to using Web Components directly, Stencil provides extra APIs that make writing fast components simpler. APIs like Virtual DOM, JSX, and async rendering make fast, powerful components easy to create, while still maintaining 100% compatibility with Web Components. + + +### What browsers can support Stencil components? + +Stencil works on modern browsers. + +[Learn more about browser support](./support-policy.md#browser-support). + + +## Stencil Project + +### How do I get involved? + +Stencil is an open source project, and we encourage you to contribute. You can start by creating issues on GitHub, submitting feature requests, and helping to replicate bugs. If you’re interested in contributing, please see our [Contributor Guide](https://github.com/ionic-team/stencil/blob/main/.github/CONTRIBUTING.md) and check out our [issue tracker](https://github.com/ionic-team/stencil/issues). + + +### Is Stencil open source? + +Yes, Stencil is open source and its source code can be [found on GitHub](https://github.com/ionic-team/stencil). Contributions are welcomed from the community. + +### Which software license does Stencil use? + +Stencil’s software [license is MIT](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### Who works on Stencil? + +The majority of the development is done by engineers at [Ionic](https://github.com/ionic-team/ionic). If you’re excited about Stencil, we encourage you to join the community and contribute! Best place to start is on the [discord channel](https://chat.stenciljs.com/). + diff --git a/versioned_docs/version-v4.18/reference/support-policy.md b/versioned_docs/version-v4.18/reference/support-policy.md new file mode 100644 index 000000000..05141a894 --- /dev/null +++ b/versioned_docs/version-v4.18/reference/support-policy.md @@ -0,0 +1,154 @@ +--- +title: Support Policy +sidebar_label: Support Policy +description: Support Policy +slug: /support-policy +--- + +# Support Policy + +## Community Maintenance + +Stencil is a 100% open source (MIT) project. Developers can ensure Stencil is the right choice for building web +components through Ionic’s community maintenance strategy. The Stencil team regularly ships new releases, bug fixes, and +is welcoming to community pull requests. + +## Stencil Maintenance and Support Status + +Given the reality of time and resource constraints as well as the desire to keep innovating in the frontend development +space, over time it becomes necessary for the Stencil team to shift focus to newer versions of the library. However, the +Stencil team will do everything it can to make the transition to newer versions as smooth as possible. The Stencil team +recommends updating to the newest version of the Stencil for the latest features, improvements and stability updates. + +The current status of each Stencil version is: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:----------------:|:------------:|:----------------:|:-----------------:| +| V4 | **Active** | Jun 26, 2023 | TBD | TBD | +| V3 | Extended Support | Jan 25, 2023 | Dec 26, 2023 | Jun 26, 2024 | +| V2 | End of Support | Aug 08, 2020 | Jul 25, 2023 | Jan 25, 2024 | +| V1 | End of Support | Jun 03, 2019 | Aug 08, 2020 | Aug 08, 2020 | + +**Maintenance Period**: Only critical bug and security fixes. No major feature improvements. + +**Extended Support Period**: Available to Stencil Enterprise customers. + +### Stencil Support Details + +Starting with Stencil v2, the Stencil team is adopting a newly revised maintenance policy. When a new major version of +Stencil is released, the previous major version release will enter maintenance mode. While a version of Stencil is in +maintenance mode, only critical bug & security fixes will be applied to that version, and no major feature improvements +will be added. The maintenance period shall last six months from the release of the new major version. + +Once the maintenance period has ended for a version of Stencil, that version enters the extended support period. During +the extended support period, only critical bug and security fixes will be applied for teams and organizations using +Stencil's Enterprise offerings. The extended support period lasts for twelve months from the release of the new major +version. + +The table below describes a theoretical timeline of releases: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:---------------------:|:------------:|:----------------:|:-----------------:| +| D | Active | Jan 01, 2022 | TBD | TBD | +| C | Maintenance | Jul 07, 2021 | Jul 01, 2022 | Jan 01, 2023 | +| B | Extended Support Only | Jan 01, 2021 | Jan 07, 2022 | Jul 07, 2022 | +| A | End of Support | Jul 07, 2020 | Jul 01, 2021 | Jan 01, 2021 | + +In the example above, when Version D is released, Version C enters maintenance mode. Version D was released on January +1st, 2022. Version C shall be in maintenance mode until July 1st, 2022, three months after the release of Version D. +After July 1st 2022, Version C will be in extended support until Jun 1st, 2023, twelve months after the release of +Version D. + +## Browser Support + +Stencil builds Web Components that run natively in all widely used desktop and mobile browsers. +Custom Elements are natively supported in Chrome, Edge, Firefox, and Safari (including iOS)! + +Stencil supports the following browsers: + +| Stencil Version | Chrome | Edge | Firefox | Safari | Internet Explorer | Pre-Chromium Edge | +|:---------------:|:------:|:----:|:-------:|:------:|:-----------------:|:-----------------:| +| V4 | v79+ | v79+ | v70+ | v14+ | ❌ | ❌ | +| V3 | v79+ | v79+ | v70+ | v14+ | ✅ | ✅ | +| V2 | v60+ | v79+ | v63+ | v10.1+ | ✅ | ✅ | + +## TypeScript Support + +Stencil acts as a compiler for a project's web components, and works closely with the TypeScript compiler to transform +TSX to vanilla JavaScript. To ensure compatibility between the two, Stencil takes an opinionated stance on which version +of the TypeScript compiler must be used. + +Stencil includes a recent copy of the TypeScript compiler in its distributable* to guarantee this compatibility. +The Stencil team is committed to keeping its version of TypeScript up to date and, as of Stencil v2.10.0, attempts to be +within one minor version of the latest TypeScript release. + +The table below describes recent versions of Stencil and the version of TypeScript each version shipped with. + +| Stencil Version | TypeScript Version | +|:---------------:|:------------------:| +| v4.16.0 | v5.4.5 | +| v4.15.0 | v5.4.4 | +| v4.14.0 | v5.4.3 | +| v4.13.0 | v5.4.2 | +| v4.10.0 | v5.3.0 | +| v4.4.0 | v5.2.2 | +| v4.2.0 | v5.1.6 | +| v3.3.0 | v5.0.4 | +| v3.0.0 | v4.9.4 | +| v2.21.0 | v4.9.3 | +| v2.20.0 | v4.8.4 | +| v2.18.0 | v4.7.4 | +| v2.14.0 | v4.5.4 | +| v2.10.0 | v4.3.5 | +| v2.5.0 | v4.2.3 | +| v2.4.0 | v4.1.3 | +| v2.2.0 | v4.0.5 | + +The TypeScript team releases a new minor version of the TypeScript compiler approximately once every three months. To +accomplish its goal of staying within one minor version of the latest release, Stencil will update its version of +TypeScript once every three months as well. Updates to the version of TypeScript will often, but not always, occur in a +[minor version release](./versioning.md#minor-release) of Stencil. + +The Stencil team acknowledges that TypeScript minor version releases may contain breaking changes. The Stencil team will +do everything in its power to avoid propagating breaking changes to its user base. + +\* The TypeScript compiler is never included in the output of your Stencil project, and is only used for compilation +and type checking purposes. + +## Compatibility Recommendations + +Stencil is in many regards an opinionated library, and includes much of the software necessary to get users building web +components as quickly as possible. There are a few pieces of software that Stencil allows users to choose to best fit +their team, organizational structure, and existing technical stack. The Stencil team has compiled a series of +compatibility tables to describe the interoperability requirements of these pieces of software and Stencil. + +### JavaScript Runtime + +| Stencil Version | Node v10 | Node v12 | Node v14 | Node v16 | Node v18 | Node v20 | Node v22 | +|:---------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| +| V4 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| V3 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | +| V2 | ❌ | ✅ | ✅ | ✅ | ⚠ | ❌ | ❌ | +| V1 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | + +### Testing Libraries + +#### Jest + +| Stencil Version | Jest v24-26 | Jest v27 | Jest v28 * | Jest v29 * | +|:---------------:|:-----------:|:--------:|:----------:|:-----------:| +| V4 | ✅ | ✅ | ✅ | ✅ | +| V3 | ✅ | ✅ | ❌ | ❌ | +| V2 | ✅ | ✅ | ❌ | ❌ | +| V1 | ✅ | ❌ | ❌ | ❌ | + +\* Support for Jest 28 & 29 has been included since Stencil v4.7.0. + +#### Puppeteer + +| Stencil Version | Puppeteer v5-9 | Puppeteer v10 | Puppeteer v11-21 | +|:---------------:|:--------------:|:-------------:|:----------------:| +| V4 | ❌ | ✅ | ✅ | +| V3 | ❌ | ✅ | ✅ | +| V2 | ✅ | ✅ | ❌ | +| V1 | ✅ | ❌ | ❌ | diff --git a/versioned_docs/version-v4.18/reference/versioning.md b/versioned_docs/version-v4.18/reference/versioning.md new file mode 100644 index 000000000..09d81c7dd --- /dev/null +++ b/versioned_docs/version-v4.18/reference/versioning.md @@ -0,0 +1,44 @@ +--- +title: Versioning +sidebar_label: Versioning +description: Versioning +slug: /versioning +--- + +# Versioning + +Stencil follows the Semantic Versioning (SemVer) convention: +major.minor.patch. Incompatible API changes increment the major version, adding +backwards-compatible functionality increments the minor version, and backwards-compatible bug fixes +increment the patch version. + +## Release Schedule + +### Major Release + +A major release will be published when there is a breaking change introduced in the API. Major releases will occur +roughly every **6 months** and may contain breaking changes. Release candidates will be published prior to a major +release in order to get feedback before the final release. An outline of what is changing and why will be included with +the release candidates. + +### Minor Release + +A minor release will be published when a new feature is added or API changes that are non-breaking are introduced. +We will heavily test any changes so that we are confident with the release, but with new code comes the potential for +new issues*. Minor releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. + +\* This statement applies to the Stencil team upgrading its version of TypeScript as well. For more information, please +see the team's [support policy regarding TypeScript](./support-policy.md#typescript-support) + +### Patch Release + +A patch release will be published when bug fixes were included, but the API has not changed and no breaking changes were +introduced. Patch releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. There may be times where patch releases need to released more often than scheduled. + +## Changelog + +To see a list of all notable changes to Stencil, please refer to the [releases +page](https://github.com/ionic-team/stencil/releases). This contains an ordered +list of all bug fixes and new features under each release. diff --git a/versioned_docs/version-v4.18/static-site-generation/01-overview.md b/versioned_docs/version-v4.18/static-site-generation/01-overview.md new file mode 100644 index 000000000..3509f33e2 --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/01-overview.md @@ -0,0 +1,49 @@ +--- +title: Static Site Generation +sidebar_label: Overview +slug: /static-site-generation +--- + +# Static Site Generation with Stencil + +One of the best ways to build fast, interactive web sites and web apps is to utilize Static Site Generation instead of Server Side Rendering (known as SSR) or Client Side Rendering (known as Single Page Apps, or SPAs). + +Static Site Generation (SSG) means building and rendering components and routes at build time (aka prerendering) rather than server request time (SSR) or at client run-time (SPA). Because a route is already prerendered, all of the content for the route is available to search engines and clients _immediately_, so SEO and performance are maximized. + +Static Site Generation doesn't mean your pages have to be and/or _stay_ static! Stencil utilizes hydration to efficiently load client-side components at runtime to get the best of both worlds. + +Since Static Site Generation prerenders components, there are some tradeoffs and things to keep in mind, but most components can be easily prerendered without much modification. + +Stencil makes SSG easy, so read on to see how to incorporate it into your apps. + +## Benefits of Static Site Generation + +- Great [Lighthouse](https://developers.google.com/web/tools/lighthouse/) scores +- Faster time to [Largest Contentful Paint (LCP)](https://web.dev/lcp/) +- Better [Search Engine Optimization (SEO)](https://support.google.com/webmasters/answer/7451184) +- Provides functionality for users with JavaScript disabled + +## How Static Site Generation and Prerendering Works + +**Build Hydrate App**: The first step in prerendering is for the compiler to generate a "hydrate" app, which is a single directory to be used by Node.js. The "hydrate" app is automatically generated when the `--prerender` CLI flag is provided and by default the app is saved to `dist/hydrate`. Prerendering uses the hydrate app internally, however it can be used directly at a lower-level. [Learn more about the Hydrate App](../guides/hydrate-app.md) + +**Fork Prerender Tasks to Available CPUs**: Stencil can efficiently divide out the prerendering to each of the current machine's CPUs using [Node.js' Child Process API](https://nodejs.org/api/child_process.html). By tasking each CPU on the machine, the compiler can drastically speed up prerendering times. + +**Prerender Index**: After the compiler has completed the build and created child processes on each available CPU, it will then kick off the prerendering by starting at the single base URL, or the configured entry URLs. Once the page has finished prerendering it'll be written to the configured `www` directory as an `index.html` file. + +**Crawl App**: During each page prerender, Stencil also collects the anchor elements and URLs used within the page. With this information, it's able to inform the main thread of which pages should be prerendered next. The main thread is in charge of orchestrating all of the URLs, and the job is finished once all of the pages have been crawled and prerendered. + +**Deploy Static Files to Production**: Now that all of the pages have been prerendered and written as static HTML files, the `www` directory can now be deployed to a server. A significant difference from prerendering and Server-side Rendering (SSR), is that the HTTP server is just serving up static HTML files rather than dynamically generating the HTML on the server. + +**Static HTML Response**: With the static HTML files deploy to a server, visitors of each prerendered page first receive the HTML with inline styles, and no blocking JS or CSS. Additionally, the compiler is already aware of the exact modules the visitor will need for this page, and will asynchronously preload the modules using [link `modulepreload`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload). + +**Client-side Hydration**: After the HTML and inlined styles have rendered the first paint, the next step is for the same nodes within the DOM to be hydrated by the client-side JavaScript. Each component within the page will asynchronously hydrate using the initial order they were found in the DOM structure. Next, as each component lazily hydrates they're able to reuse the existing nodes found in the DOM. + +## Tooling + +To be clear, Stencil does _not_ use `Puppeteer` or `jsdom` for prerendering. Puppeteer is great for End-to-End +testing, but for performance reasons it's not ideal to quickly generate a large website with hundreds or thousands of pages. Additionally, `jsdom` is often used for unit testing, but in our experience it's difficult to use with async components and its global environment nature. + +Instead, Stencil uses its own internal DOM APIs which strictly follow the web standards, but optimized for prerendering, Static Site Generation and Server-side Rendering. By doing so, developers can still use all the same APIs they're already familiar with, but they'll seamlessly work within a NodeJS environment too. This means developers often do not have to write code differently in how they're building components, but rather they focus only on writing one type of component, and coding it using the standards they already know. To reiterate, developers do not have to learn a new API for prerendering. It's just the same web APIs your components are already using. + +Every component, machine and environment will perform differently, so it's difficult to provide a consistent benchmark. However, what we do know is that [Ionic's Documentation site](https://ionicframework.com/docs) has hundreds of pages and Stencil is able to prerender the entire site in a few seconds. diff --git a/versioned_docs/version-v4.18/static-site-generation/_category_.json b/versioned_docs/version-v4.18/static-site-generation/_category_.json new file mode 100644 index 000000000..000fe5643 --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Static Site Generation", + "position": 4 +} diff --git a/versioned_docs/version-v4.18/static-site-generation/basics.md b/versioned_docs/version-v4.18/static-site-generation/basics.md new file mode 100644 index 000000000..573c5aa52 --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/basics.md @@ -0,0 +1,72 @@ +--- +title: Static Site Generation Basics in Stencil +sidebar_label: Basics +description: Quick introduction to configuring and using Static Site Generation in Stencil +slug: /static-site-generation-basics +--- + +# Static Site Generation Basics + +Rendering components at build time (rather than purely server or client-time), can add significant performance improvements to your app, and maximize SEO impact. + +Using Static Site Generation in Stencil requires running a build command, returning promises from component lifecycle methods that fetch dynamic data, and ensuring all known URLs are properly discovered and built. + +## Static Build + +Stencil doesn't prerender components by default. However, the build can be made to prerender using the `--prerender` flag: + +```bash +stencil build --prerender +``` + +## Rendering Dynamic Data + +Many components need to render based on data fetched from a server. Stencil handles this by allowing components to return `Promise`'s from lifecycle methods like `componentWillLoad` (this can be achieved by using `async/await` as well). + +For example, this is how to have Stencil wait to render a component until it fetches data from the server: + +```typescript +async componentWillLoad() { + const ret = await fetch('https://.../api'); + + this.thing = await ret.json(); +} +``` + +## Integration with a Router + +Since Stencil will actually navigate to and execute components, it has full support for a router, including Stencil Router. + +There are no changes necessary to access route params and matches. However, make sure your routes can accept a trailing slash as prerendered static content will be treated as loading an `index.html` file at that path, and so the browser may append a trailing slash. + +In particular, if using Stencil Router, double check usage of `exact={true}` which could cause your routes to not match when loaded with a trailing slash. + +## Page and URL Discovery + +By default, Stencil crawls your app starting at base URL of `/` and discovers all paths that need to be indexed. By default this will only discover pages that are linked at build time, but can be easily configured to build any possible URL for the app. + +As each page is generated and new links are found, Stencil will continue to crawl and prerender pages. + +See the [prerender config](./prerender-config.md) docs to see how this can be customized further. + + +## Things to Watch For + +There may be some areas of your code that should absolutely not run while prerendering. To help avoid certain code Stencil provides a `Build.isBrowser` build conditional to tell prerendering to skip over. Here is an example of how to use this utility: + +```tsx +import { Build } from '@stencil/core'; + +connectedCallback() { + // Build.isBrowser is true when running in the + // browser and false when being prerendered + + if (Build.isBrowser) { + console.log('running in browser'); + } else { + console.log('running in node while prerendering'); + } +} +``` + +Also note that the actual runtime generated for the browser builds will not include code that has been excluded because of the `if (Build.isBrowser)` statement. In the above example, only `console.log('running in browser')` would be included within the component's runtime. diff --git a/versioned_docs/version-v4.18/static-site-generation/deployment.md b/versioned_docs/version-v4.18/static-site-generation/deployment.md new file mode 100644 index 000000000..b76972bcd --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/deployment.md @@ -0,0 +1,16 @@ +--- +title: Deploying a Static Site +sidebar_label: Deployment +description: Deploying a Static Site +slug: /static-site-generation-deployment +--- + +# Deploying a Stencil Static Site + +Deploying a prerendered static site built with Stencil is exactly like deploying any static site, because the output is just a set of HTML files. + +Every path that Stencil detects (or is provided using `entryUrls` in the prerender config) is generated in the `www` output target's directory, with each url given an `index.html` that becomes the root for the app. + +Think of it as turning every URL in your app into a standalone web page that bootstraps the entire app. No matter what URL a visitor comes to, they will be served an `index.html` file with that page's specific content already rendered, but with the entire app then hydrating and loading. + +This means you can simply deploy the `www` output target's directory to any static host! \ No newline at end of file diff --git a/versioned_docs/version-v4.18/static-site-generation/meta.md b/versioned_docs/version-v4.18/static-site-generation/meta.md new file mode 100644 index 000000000..606e49072 --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/meta.md @@ -0,0 +1,37 @@ +--- +title: SEO Meta Tags in SSG +sidebar_label: Meta tags +description: Managing meta tags for SEO and social media embedding in Stencil Static Sites +slug: /static-site-generation-meta-tags +--- + +# SEO Meta Tags and Static Site Generation + +Web Apps need to list detailed meta information about content in order to maximize SEO and provide good social media embed experiences. + +One of the benefits to Stencil's prerendering is that most DOM apis are available in the NodeJS environment too. +For example, to set the document title, simply run `document.title = "Page Title"`. +Similarly, meta tags can be set using standard DOM APIs as found in the browser, such as `document.head` and `document.createElement('meta')`. +For this reason, your component's runtime can take care of much of this custom work during prerendering. + +That said, the Prerender Config also includes options that allow individual pages to be modified arbitrarily during prerendering. +For example, the `afterHydrate(document, url)` hook can be used to update the parsed `document` before it is serialized into an HTML string. +The `document` argument is a [standard `Document`](https://developer.mozilla.org/en-US/docs/Web/API/Document), while the `url` argument is a [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) for the location of the page being rendered. + +In the example below, the `afterHydrate(document, url)` hook is setting the document title from url's pathname. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + afterHydrate(document, url) { + document.title = url.pathname; + } +}; +``` + +## @stencil/helmet + +The `@stencil/helmet` package was a library for managing meta tags dynamically. +It has since been deprecated. +For additional information regarding this package, please see its [GitHub page](https://github.com/ionic-team/stencil-helmet) diff --git a/versioned_docs/version-v4.18/static-site-generation/prerender-config.md b/versioned_docs/version-v4.18/static-site-generation/prerender-config.md new file mode 100644 index 000000000..c94144943 --- /dev/null +++ b/versioned_docs/version-v4.18/static-site-generation/prerender-config.md @@ -0,0 +1,106 @@ +--- +title: Prerender Config +sidebar_label: Prerender Config +description: Prerender Config +slug: /prerender-config +--- + + +# Prerender Config for Static Site Generation (SSG) + +As of `1.13.0`, the optional prerender config can be used while prerendering a `www` output target. The `prerender.config.ts` file can further update the parsed document of each page, before it is serialized to HTML. + +Within `stencil.config.ts`, set the path to the prerendering config file path using the `prerenderConfig` +property, such as: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + baseUrl: 'https://stenciljs.com/', + prerenderConfig: './prerender.config.ts', + } + ] +}; +``` + +Next, inside of the `prerender.config.ts` file, it should export a `config` object using the `PrerenderConfig` interface. + +```tsx +import { PrerenderConfig } from '@stencil/core'; +export const config: PrerenderConfig = { + ... +}; +``` + +| Config | Description | Default | +|--------|-------------|---------| +| `afterHydrate(document, url)` | Run after each `document` is hydrated, but before it is serialized into an HTML string. Hook is passed the `document` and its `URL`. | | +| `beforeHydrate(document, url)` | Run before each `document` is hydrated. Hook is passed the `document` it's `URL`. | | +| `afterSerializeTemplate(html)` | Runs after the template Document object has serialize into an HTML formatted string. Returns an HTML string to be used as the base template for all prerendered pages. | | +| `beforeSerializeTemplate(document)` | Runs before the template Document object is serialize into an HTML formatted string. Returns the Document to be serialized which will become the base template html for all prerendered pages. | | +| `canonicalUrl(url)` | A hook to be used to generate the canonical `` tag which goes in the `` of every prerendered page. Returning `null` will not add a canonical url tag to the page. | | +| `crawlUrls` | While prerendering, crawl same-origin URLs found within `` elements. | `true` | +| `entryUrls` | URLs to start the prerendering from. By default the root URL of `/` is used. | `['/']` | +| `filterAnchor(attrs, base)` | Return `true` the given `` element should be crawled or not. | | +| `filterUrl(url, base)` | Return `true` if the given URL should be prerendered or not. | | +| `filePath(url, filePath)` | Returns the file path which the prerendered HTML content should be written to. | | +| `hydrateOptions(url)` | Returns the hydrate options to use for each individual prerendered page. | | +| `loadTemplate(filePath)` | Returns the template file's content. The template is the base HTML used for all prerendered pages. | | +| `normalizeUrl(href, base)` | Used to normalize the page's URL from a given a string and the current page's base URL. Largely used when reading an anchor's `href` attribute value and normalizing it into a `URL`. | | +| `staticSite` | Static Site Generated (SSG). Does not include Stencil's client-side JavaScript, custom elements or preload modules. | `false` | +| `trailingSlash` | If the prerendered URLs should have a trailing "/"" or not | `false` | + + +## Individual Page Hydrate Options + +Beyond settings for the entire prerendering process with `prerender.config.ts`, you can also +set individual hydrate options per each page. The `hydrateOptions(url)` hook can be used to further configure each page. Below is an example of the prerender config with the `hydrateOptions()` hook, which returns options for each page. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + hydrateOptions(url) { + return { + prettyHtml: true + }; + } +}; + + +``` +| Option | Description | Default | +|--------|-------------|---------| +| `addModulePreloads` | Adds `` for modules that will eventually be requested. | `true` | +| `approximateLineWidth` | Sets an approximate line width the HTML should attempt to stay within. Note that this is "approximate", in that HTML may often not be able to be split at an exact line width. Additionally, new lines created is where HTML naturally already has whitespace, such as before an attribute or spaces between words. | `100` | +| `canonicalUrl` | Sets the `href` attribute on the `` tag within the ``. If the value is not defined it will ensure a canonical link tag is no included in the ``. | | +| `clientHydrateAnnotations` | Include the HTML comments and attributes used by the client-side JavaScript to read the structure of the HTML and rebuild each component. | `true` | +| `constrainTimeouts` | Constrain `setTimeout()` to 1ms, but still async. Also only allows `setInterval()` to fire once, also constrained to 1ms. | `true` | +| `cookie` | Sets `document.cookie`. | | +| `direction` | Sets the `dir` attribute on the top level ``. | | +| `excludeComponents` | Component tag names listed here will not be prerendered, nor will hydrated on the client-side. Components listed here will be ignored as custom elements and treated no differently than a `
    `. | | +| `inlineExternalStyleSheets` | External stylesheets from `` are instead inlined into ` + + +``` + +## Style Modes + +Component Style Modes enable you to create versatile designs for your components by utilizing different styling configurations. This is achieved by assigning the styleUrls property of a component to a collection of style mode names, each linked to their respective CSS files. + +### Example: Styling a Button Component + +Consider a basic button component that supports both iOS and Material Design aesthetics: + +```tsx title="Using style modes to style a component" +@Component({ + tag: 'simple-button', + styleUrls: { + md: './simple-button.md.css', // styles for Material Design + ios: './simple-button.ios.css' // styles for iOS + }, +}) +export class SimpleButton { + // ... +} +``` + +In the example above, two different modes are declared. One mode is named `md` (for 'Material Design') and refers back to a Material Design-specific stylesheet. Likewise, the other is named `ios` (for iOS) and references a different stylesheet for iOS-like styling. Both stylesheets are relative paths to the file that declares the component. While we have chosen short names in the above example, there's no limitation to the keys used in the `styleUrls` object. + +To dictate the style mode (Material Design or iOS) in which the button should be rendered, you must initialize the desired mode before any component rendering occurs. This can be done as follows: + +```ts +import { setMode } from '@stencil/core'; +setMode(() => 'ios'); // Setting iOS as the default mode for all components +``` + +The `setMode` function processes all elements, enabling the assignment of modes individually based on specific element attributes. For instance, by assigning the `mode` attribute to a component: + +```html + +``` + +You can conditionally set the style mode based on the `mode` property: + +```ts +import { setMode } from '@stencil/core'; + +const defaultMode = 'md'; // Default to Material Design +setMode((el) => el.getAttribute('mode') || defaultMode); +``` + +The reason for deciding which mode to apply can be very arbitrary and based on your requirements, using an element property called `mode` is just one example. + +### Important Considerations + +- __Initialization:__ Style modes must be defined at the start of the component lifecycle and cannot be changed thereafter. If you like to change the components mode dynamically you will have to re-render it entirely. +- __Usage Requirement:__ A style mode must be set to ensure the component loads with styles. Without specifying a style mode, the component will not apply any styles. +- __Input Validation:__ Verify a style mode is supported by a component you are setting it for. Setting an un-supported style mode keeps the component unstyled. +- __Querying Style Mode:__ To check the current style mode and e.g. provide different functionality based on the mode, use the `getMode` function: + +```ts +import { getMode } from '@stencil/core'; + +const simpleButton = document.queryElement('simple-button') +console.log(getMode(simpleButton)); // Outputs the current style mode of component +``` + +This approach ensures your components are adaptable and can dynamically switch between different styles, enhancing the user experience across various platforms and design preferences. + +## Global styles + +While most styles are usually scoped to each component, sometimes it's useful to have styles that are available to all the components in your project. To create styles that are globally available, start by creating a global stylesheet. For example, you can create a folder in your `src` directory called `global` and create a file called `global.css` within that. Most commonly, this file is used to declare CSS custom properties on the root element via the `:root` pseudo-class. This is because styles provided via the `:root` pseudo-class can pass through the shadow boundary. For example, you can define a primary color that all your components can use. + +```css +:root { + --color-primary: blue; +} +``` + +In addition to CSS custom properties, other use cases for a global stylesheet include + +- Theming: defining CSS variables used across the app +- Load fonts with `@font-face` +- App wide font-family +- CSS resets + +To make the global styles available to all the components in your project, the `stencil.config.ts` file comes with an optional [`globalStyle` setting](../config/01-overview.md#globalstyle) that accepts the path to your global stylesheet. + +```tsx +export const config: Config = { + namespace: 'app', + globalStyle: 'src/global/global.css', + outputTarget: [ + { + type: 'www', + }, + ], +}; +``` + +The compiler will run the same minification, autoprefixing, and plugins over `global.css` and generate an output file for the [`www`](../output-targets/www.md) and [`dist`](../output-targets/dist.md) output targets. The generated file will always have the `.css` extension and be named as the specified `namespace`. + +In the example above, since the namespace is `app`, the generated global styles file will be located at: `./www/build/app.css`. + +This file must be manually imported in the `index.html` of your application. + +```html + +``` diff --git a/versioned_docs/version-v4.19/components/templating-and-jsx.md b/versioned_docs/version-v4.19/components/templating-and-jsx.md new file mode 100644 index 000000000..43847d481 --- /dev/null +++ b/versioned_docs/version-v4.19/components/templating-and-jsx.md @@ -0,0 +1,471 @@ +--- +title: Using JSX +sidebar_label: Using JSX +description: Using JSX +slug: /templating-jsx +--- + +# Using JSX + +Stencil components are rendered using JSX, a popular, declarative template syntax. Each component has a `render` function that returns a tree of components that are rendered to the DOM at runtime. + +## Basics + +The `render` function is used to output a tree of components that will be drawn to the screen. + +```tsx +class MyComponent { + render() { + return ( +
    +

    Hello World

    +

    This is JSX!

    +
    + ); + } +} +``` + +In this example we're returning the JSX representation of a `div`, with two child elements: an `h1` and a `p`. + +### Host Element + +If you want to modify the host element itself, such as adding a class or an attribute to the component itself, use the `` functional component. Check for more details [here](./host-element.md) + + +## Data Binding + +Components often need to render dynamic data. To do this in JSX, use `{ }` around a variable: + +```tsx +render() { + return ( +
    Hello {this.name}
    + ) +} +``` + +:::note +If you're familiar with ES6 template variables, JSX variables are very similar, just without the `$`: +::: + +```tsx +//ES6 +`Hello ${this.name}` + +//JSX +Hello {this.name} +``` + + +## Conditionals + +If we want to conditionally render different content, we can use JavaScript if/else statements: +Here, if `name` is not defined, we can just render a different element. + +```tsx +render() { + if (this.name) { + return (
    Hello {this.name}
    ) + } else { + return (
    Hello, World
    ) + } +} +``` + +Additionally, inline conditionals can be created using the JavaScript ternary operator: + +```tsx +render() { + return ( +
    + {this.name + ?

    Hello {this.name}

    + :

    Hello World

    + } +
    + ); +} +``` + +**Please note:** Stencil reuses DOM elements for better performance. Consider the following code: + +```tsx +{someCondition + ? + : +} +``` + +The above code behaves exactly the same as the following code: + +```tsx + +``` + +Thus, if `someCondition` changes, the internal state of `` won't be reset and its lifecycle methods such as `componentWillLoad()` won't fire. Instead, the conditional merely triggers an update to the very same component. + +If you want to destroy and recreate a component in a conditional, you can assign the `key` attribute. This tells Stencil that the components are actually different siblings: + +```tsx +{someCondition + ? + : +} +``` + +This way, if `someCondition` changes, you get a new `` component with fresh internal state that also runs the lifecycle methods `componentWillLoad()` and `componentDidLoad()`. + + +## Slots + +Components often need to render dynamic children in specific locations in their component tree, allowing a developer to supply child content when using our component, with our component placing that child component in the proper location. + +To do this, you can use the [Slot](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) tag inside of your `my-component`. + +```tsx +// my-component.tsx + +render() { + return ( +
    +

    A Component

    +
    +
    + ); +} + +``` + +Then, if a user passes child components when creating our component `my-component`, then `my-component` will place that +component inside of the second `
    ` above: + +```tsx +render(){ + return( + +

    Child Element

    +
    + ) +} +``` + +Slots can also have `name`s to allow for specifying slot output location: + +```tsx +// my-component.tsx + +render(){ + return [ + , +

    Here is my main content

    , + + ] +} +``` + +```tsx +render(){ + return( + +

    I'll be placed before the h1

    +

    I'll be placed after the h1

    +
    + ) +} +``` + +### Slots Outside Shadow DOM + +:::caution +Slots are native to the [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), but Stencil polyfills +the behavior to work for non-shadow components as well. However, you may encounter issues using slots outside the Shadow DOM especially with +component trees mixing shadow and non-shadow components, or when passing a slot through many levels of components. In many cases, this behavior can +be remedied by wrapping the `slot` in an additional element (like a `div` or `span`) so the Stencil runtime can correctly "anchor" the relocated +content in its new location. +::: + +There are known use cases that the Stencil runtime is not able to support: + +- Forwarding slotted content to another slot with a different name:
    + It is recommended that slot names stay consistent when slotting content through multiple levels of components. **Avoid** defining slot tags like + ``. + +## Dealing with Children + +The children of a node in JSX correspond at runtime to an array of nodes, +whether they are created by mapping across an array with +[`Array.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) +or simply declared as siblings directly in JSX. This means that at runtime the +children of the two top-level divs below (`.todo-one` and `.todo-two`) will be +represented the same way: + + +```tsx +render() { + return ( + <> +
    + {this.todos.map((todo) => ( + { todo.taskName } + )} +
    +
    + { todos[0].taskName } + { todos[1].taskName } +
    + + ) +} +``` + +If this array of children is dynamic, i.e., if any nodes may be added, +removed, or reordered, then it's a good idea to set a unique `key` attribute on +each element like so: + +```tsx +render() { + return ( +
    + {this.todos.map((todo) => ( +
    +
    {todo.taskName}
    +
    + ))} +
    + ) +} +``` + +When nodes in a children array are rearranged Stencil makes an effort to +preserve DOM nodes across renders but it isn't able to do so in all cases. +Setting a `key` attribute lets Stencil ensure it can match up new and old +children across renders and thereby avoid recreating DOM nodes unnecessarily. + +:::caution +Do not use an array index or some other non-unique value as a key. Try to +ensure that each child has a key which does not change and which is unique +among all its siblings. +::: + +### Automatic Key Insertion + +During compilation Stencil will automatically add key attributes to any JSX +nodes in your component's render method which are not nested within curly +braces. This allows Stencil’s runtime to accurately reconcile children when +their order changes or when a child is conditionally rendered. + +For instance, consider a render method looking something like this: + +```tsx + render() { + return ( +
    + { this.disabled &&
    no key!
    } +
    + +
    +
    + ); + } +``` + +While it might seem like adding a key attribute to the `#slot-wrapper` div +could help ensure that elements will be matched up correctly when the component +re-renders, this is actually superfluous because Stencil will automatically add +a key to that element when it compiles your component. + +:::note +The Stencil compiler can only safely perform automatic key insertion in certain +scenarios where there is no danger of the keys accidentally causing elements to +be considered different when they should be treated the same (or vice versa). + +In particular, the compiler will not automatically insert `key` attributes if a +component's `render` method has more than one `return` statement or if it +returns a [conditional +expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator). +Additionally, the compiler will not add key attributes to any JSX which is +found within curly braces (`{ }`). +::: + +## Handling User Input + +Stencil uses native [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events). + +Here's an example of handling a button click. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private handleClick = () => { + alert('Received the button click!'); + } + + render() { + return ( + + ); + } +} +``` + +Here's another example of listening to input `change`. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private inputChanged = (event: Event) => { + console.log('input changed: ', (event.target as HTMLInputElement).value); + } + + render() { + return ( + + ); + } +} +``` + + +## Complex Template Content + +So far we've seen examples of how to return only a single root element. We can also nest elements inside our root element + +In the case where a component has multiple "top level" elements, the `render` function can return an array. +Note the comma in between the `
    ` elements. + +```tsx +render() { + return ([ + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    , + + // second top level element, note the , above +
    + ... more html content ... +
    + ]); +} +``` + +Alternatively you can use the `Fragment` functional component, in which case you won't need to add commas: + +```tsx +import { Fragment } from '@stencil/core'; +... +render() { + return ( + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    + +
    + ... more html content ... +
    +
    ); +} +``` + +It is also possible to use `innerHTML` to inline content straight into an element. This can be helpful when, for example, loading an svg dynamically and then wanting to render that inside of a `div`. This works just like it does in normal HTML: + +```markup +
    +``` + +## Getting a reference to a DOM element + +In cases where you need to get a direct reference to an element, like you would normally do with `document.querySelector`, you might want to use a `ref` in JSX. Lets look at an example of using a `ref` in a form: + +```tsx +@Component({ + tag: 'app-home', +}) +export class AppHome { + + textInput!: HTMLInputElement; + + handleSubmit = (event: Event) => { + event.preventDefault(); + console.log(this.textInput.value); + } + + render() { + return ( +
    + + +
    + ); + } +} +``` + +In this example we are using `ref` to get a reference to our input `ref={(el) => this.textInput = el as HTMLInputElement}`. We can then use that ref to do things such as grab the value from the text input directly `this.textInput.value`. + + +## Avoid Shared JSX Nodes + +The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be shared within the same renderer. + +In the example below, the `sharedNode` variable is reused multiple times within the `render()` function. The renderer is able to optimize its DOM element lookups by caching the reference, however, this causes issues when nodes are reused. Instead, it's recommended to always generate unique nodes like the changed example below. + +```diff +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + render() { +- const sharedNode =
    Text
    ; + return ( +
    +- {sharedNode} +- {sharedNode} ++
    Text
    ++
    Text
    +
    + ); + } +} +``` + +Alternatively, creating a factory function to return a common JSX node could be used instead since the returned value would be a unique instance. For example: + +```tsx +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + getText() { + return
    Text
    ; + } + + render() { + return ( +
    + {this.getText()} + {this.getText()} +
    + ); + } +} +``` + +## Other Resources + +- [Understanding JSX for StencilJS Applications](https://www.joshmorony.com/understanding-jsx-for-stencil-js-applications/) diff --git a/versioned_docs/version-v4.19/config/01-overview.md b/versioned_docs/version-v4.19/config/01-overview.md new file mode 100644 index 000000000..2ddb413cf --- /dev/null +++ b/versioned_docs/version-v4.19/config/01-overview.md @@ -0,0 +1,522 @@ +--- +title: Config +sidebar_label: Overview +description: Config +slug: /config +--- + +# Stencil Config + +In most cases, the `stencil.config.ts` file does not require any customization since Stencil comes with great default values out-of-the-box. In general, it's preferred to keep the config as minimal as possible. In fact, you could even delete the `stencil.config.ts` file entirely and an app would compile just fine. But at the same time, the compiler can be configured at the lowest levels using this config. Below are the many *optional* config properties. + +Example `stencil.config.ts`: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'MyApp', + srcDir: 'src' +}; +``` + +## buildDist + +*default: true (prod), false (dev)* + +Sets whether or not Stencil will execute output targets and write output to +`dist/` when `stencil build` is called. Defaults to `false` when building for +development and `true` when building for production. If set to `true` then +Stencil will always build all output targets, regardless of whether the build +is in dev or prod mode or using watch mode. + +```tsx +buildDist: true +``` + +## buildEs5 + +Sets if the ES5 build should be generated or not. +It defaults to `false`. +Setting `buildEs5` to `true` will also create ES5 builds for both dev and prod modes. +Setting `buildEs5` to `prod` will only build ES5 in prod mode. + +```tsx +buildEs5: boolean | 'prod' +``` + +## bundles + +By default, Stencil will statically analyze the application and generate a component graph of how all the components are interconnected. From the component graph it is able to best decide how components should be grouped depending on their usage with one another within the app. By doing so it's able to bundle components together in order to reduce network requests. However, bundles can be manually generated using the `bundles` config. + +The `bundles` config is an array of objects that represent how components are grouped together in lazy-loaded bundles. This config is rarely needed as Stencil handles this automatically behind the scenes. + +```tsx +bundles: [ + { components: ['ion-button'] }, + { components: ['ion-card', 'ion-card-header'] } +] +``` + +## cacheDir + +*default: '.stencil'* + +The directory where sub-directories will be created for caching when [`enableCache`](#enablecache) is set `true` or if using +[Stencil's Screenshot Connector](../testing/stencil-testrunner/07-screenshot-connector.md). + +A Stencil config like the following: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + enableCache: true, + cacheDir: '.cache', + testing: { + screenshotConnector: 'connector.js' + } +} +``` + +Will result in the following file structure: + +```tree +stencil-project-root +└── .cache + ├── .build <-- Where build related file caching is written + | + └── screenshot-cache.json <-- Where screenshot caching is written +``` + +## devServer + +Please see the [Dev-Server docs](./dev-server.md). + +## enableCache + +*default: `true`* + +Stencil will cache build results in order to speed up rebuilds. To disable this feature, set `enableCache` to `false`. + +```tsx +enableCache: true +``` + +## extras + +Please see the [Extras docs](./extras.md). + +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + +## generateExportMaps + +*default: `false`* + +Stencil will generate [export maps](https://nodejs.org/api/packages.html#packages_exports) that correspond with various output target outputs. This includes the root +entry point based on the [primary output target](../output-targets/01-overview.md#primary-package-output-target-validation) (or first eligible output target if not specified), +the entry point for the lazy-loader (if using the `dist` output target), and entry points for each component (if using `dist-custom-elements`). + +## globalScript + +The global script config option takes a file path as a string. + +The global script runs once before your library/app loads, so you can do things like setting up a connection to an external service or configuring a library you are using. + +The code to be executed should be placed within a default function that is exported by the global script. Ensure all of the code in the global script is wrapped in the function that is exported: + +```javascript +export default function() { // or export default async function() + initServerConnection(); +} +``` + +:::note +The exported function can also be `async` but be aware that this can have implications on the performance of your application as all rendering operations will be deferred until after the global script finishes. +::: + +## globalStyle + +Stencil is traditionally used to compile many components into an app, and each component comes with its own compartmentalized styles. However, it's still common to have styles which should be "global" across all components and the website. A global CSS file is often useful to set [CSS Variables](../components/styling.md). + +Additionally, the `globalStyle` config can be used to precompile styles with Sass, PostCSS, etc. + +Below is an example folder structure containing a webapp's global css file, named `app.css`. + +```bash +src/ + components/ + global/ + app.css +``` + +The global style config takes a file path as a string. The output from this build will go to the `buildDir`. In this example it would be saved to `www/build/app.css`. + +```tsx +globalStyle: 'src/global/app.css' +``` + +Check out the [styling docs](../components/styling.md#global-styles) of how to use global styles in your app. + +## hashedFileNameLength + +*default: `8`* + +When the `hashFileNames` config is set to `true`, and it is a production build, the `hashedFileNameLength` config is used to determine how many characters the file name's hash should be. + +```tsx +hashedFileNameLength: 8 +``` + +## hashFileNames + +*default: `true`* + +During production builds, the content of each generated file is hashed to represent the content, and the hashed value is used as the filename. If the content isn't updated between builds, then it receives the same filename. When the content is updated, then the filename is different. By doing this, deployed apps can "forever-cache" the build directory and take full advantage of content delivery networks (CDNs) and heavily caching files for faster apps. + +```tsx +hashFileNames: true +``` + +## hydratedFlag + +When using the [lazy build](https://stenciljs.com/docs/distribution) Stencil +has support for automatically applying a class or attribute to a component and +all of its child components when they have finished hydrating. This can be used +to prevent a [flash of unstyled content +(FOUC)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content), a +typically-undesired 'flicker' of unstyled HTML that might otherwise occur +during component rendering while various components are asynchronously +downloaded and rendered. + +By default, Stencil will add the `hydrated` CSS class to elements to indicate +hydration. The `hydratedFlag` config field allows this behavior to be +customized, by changing the name of the applied CSS class, setting it to use an +attribute to indicate hydration, or changing which type of CSS properties and +values are assigned before and after hydrating. This config can also be used to +turn off this behavior by setting it to `null`. + +If a Stencil configuration does not supply a value for `hydratedFlag` then +Stencil will automatically generate the following default configuration: + +```ts +const defaultHydratedFlag: HydratedFlag = { + hydratedValue: 'inherit', + initialValue: 'hidden', + name: 'hydrated', + property: 'visibility', + selector: 'class', +}; +``` + +If `hydratedFlag` is explicitly set to `null`, Stencil will not set a default +configuration and the behavior of marking hydration with a class or attribute +will be disabled. + +```tsx +hydratedFlag: null | { + name?: string, + selector?: 'class' | 'attribute', + property?: string, + initialValue?: string, + hydratedValue?: string +} +``` + +The supported options are as follows: + +### name + +*default: 'hydrated'* + +The name which Stencil will use for the attribute or class that it sets on +elements to indicate that they are hydrated. + +```tsx +name: string +``` + +### selector + +*default: 'class'* + +The way that Stencil will indicate that a component has been hydrated. When +`'class'`, Stencil will set the `name` option on the element as a class, and +when `'attribute'`, Stencil will similarly set the `name` option as an +attribute. + +```tsx +selector: 'class' | 'attribute' +``` + +### property + +*default: 'visibility'* + +The CSS property used to show and hide components. This defaults to the CSS +`visibility` property. Other possible CSS properties might include `display` +with the `initialValue` setting as `none`, or `opacity` with the `initialValue` +as `0`. Defaults to `visibility`. + +```tsx +property: string +``` + +### initialValue + +*default: 'hidden'* + +This is the value which should be set for the property specified by `property` +on all components before hydration. + +```tsx +initialValue: string +``` + +### hydratedValue + +*default: 'inherit'* + +This is the value which should be set for the property specified by `property` +on all components once they've completed hydration. + +```tsx +hydratedValue: string +``` + +## invisiblePrehydration + +*default: `true`* + +When `true`, `invisiblePrehydration` will visually hide components before they are hydrated by adding an automatically injected style tag to the document's head. Setting `invisiblePrehydration` to `false` will not inject the style tag into the head, allowing you to style your web components pre-hydration. + +:::note +Setting `invisiblePrehydration` to `false` will cause everything to be visible when your page is loaded, causing a more prominent Flash of Unstyled Content (FOUC). However, you can style your web component's fallback content to your preference. +::: + +```tsx +invisiblePrehydration: true +``` + +## minifyCss + +_default: `true` in production_ + +When `true`, the browser CSS file will be minified. + +## minifyJs + +_default: `true` in production_ + +When `true`, the browser JS files will be minified. Stencil uses [Terser](https://terser.org/) under-the-hood for file minification. + +## namespace + +*default: `App`* + +The `namespace` config is a `string` representing a namespace for the app. For apps that are not meant to be a library of reusable components, the default of `App` is just fine. However, if the app is meant to be consumed as a third-party library, such as `Ionic`, a unique namespace is required. + +```tsx +namespace: "Ionic" +``` +## outputTargets + +Please see the [Output Target docs](../output-targets/01-overview.md). + +## plugins + +Please see the [Plugin docs](./plugins.md). + +## preamble + +*default: `undefined`* + +Used to help to persist a banner or add relevant information about the resulting build, the `preamble` configuration +field is a `string` that will be converted into a pinned comment and placed at the top of all emitted JavaScript files, +with the exception of any emitted polyfills. Escaped newlines may be placed in the provided value for this field and +will be honored by Stencil. + +Example: +```tsx +preamble: 'Built with Stencil\nCopyright (c) SomeCompanyInc.' +``` +Will generate the following comment: +```tsx +/*! + * Built with Stencil + * Copyright (c) SomeCompanyInc. + */ +``` + +## sourceMap + +*default: `true`* + +When omitted or set to `true`, sourcemaps will be generated for a project. +When set to `false`, sourcemaps will not be generated. + +```tsx +sourceMap: true | false +``` + +Sourcemaps create a translation between Stencil components that are written in TypeScript/JSX and the resulting +JavaScript that is output by Stencil. Enabling source maps in your project allows for an improved debugging experience +for Stencil components. For example, they allow external tools (such as an Integrated Development Environment) to add +breakpoints directly in the original source code, which allows you to 'step through' your code line-by-line, to inspect +the values held in variables, to observe logic flow, and more. + +Please note: Stencil will always attempt to minify a component's source code as much as possible during compilation. +When `sourceMap` is enabled, it is possible that a slightly different minified result will be produced by Stencil when +compared to the minified result produced when `sourceMap` is not enabled. + +Developers are responsible for determining whether or not they choose to serve sourcemaps in each environment their +components are served and implementing their decision accordingly. + +## srcDir + +*default: `src`* + +The `srcDir` config specifies the directory which should contain the source typescript files for each component. The standard for Stencil apps is to use `src`, which is the default. + +```tsx +srcDir: 'src' +``` + +## taskQueue + +*default: `async`* + +Sets the task queue used by stencil's runtime. The task queue schedules DOM read and writes +across the frames to efficiently render and reduce layout thrashing. By default, the +`async` is used. It's recommended to also try each setting to decide which works +best for your use-case. In all cases, if your app has many CPU intensive tasks causing the +main thread to periodically lock-up, it's always recommended to try +[Web Workers](../guides/workers.md) for those tasks. + +* `congestionAsync`: DOM reads and writes are scheduled in the next frame to prevent layout + thrashing. When the app is heavily tasked and the queue becomes congested it will then + split the work across multiple frames to prevent blocking the main thread. However, it can + also introduce unnecessary reflows in some cases, especially during startup. `congestionAsync` + is ideal for apps running animations while also simultaneously executing intensive tasks + which may lock-up the main thread. + +* `async`: DOM read and writes are scheduled in the next frame to prevent layout thrashing. + During intensive CPU tasks it will not reschedule rendering to happen in the next frame. + `async` is ideal for most apps, and if the app has many intensive tasks causing the main + thread to lock-up, it's recommended to try [Web Workers](../guides/workers.md) + rather than the congestion async queue. + +* `immediate`: Makes writeTask() and readTask() callbacks to be executed synchronously. Tasks + are not scheduled to run in the next frame, but do note there is at least one microtask. + The `immediate` setting is ideal for apps that do not provide long-running and smooth + animations. Like the async setting, if the app has intensive tasks causing the main thread + to lock-up, it's recommended to try [Web Workers](../guides/workers.md). + +```tsx +taskQueue: 'async' +``` + +## testing + +Please see the [testing config docs](../testing/stencil-testrunner/02-config.md). + +## transformAliasedImportPaths + +*default: `true`* + +This sets whether or not Stencil should transform [path aliases]( +https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) set +in a project's `tsconfig.json` from the assigned module aliases to resolved +relative paths. This will not transform external imports (like `@stencil/core`) or +relative imports (like `'../utils'`). + +This option applies globally and will affect all code processed by Stencil, +including `.d.ts` files and spec tests. + +An example of path transformation could look something like the following. + +First, a set of `paths` aliases in `tsconfig.json`: + +```json title="tsconfig.json" +{ + "compilerOptions": { + "paths": { + "@utils": [ + "../path/to/utils" + ] + } + } +} +``` + +Then with the following input: + +```ts title="src/my-module.ts" +import { utilFunc, UtilInterface } from '@utils' + +export function util(arg: UtilInterface) { + utilFunc(arg) +} +``` + +Stencil will produce the following output: + +```js title="dist/my-module.js" +import { utilFunc } from '../path/to/utils'; +export function util(arg) { + utilFunc(arg); +} +``` + +```ts title="dist/my-module.d.ts" +import { UtilInterface } from '../path/to/utils'; +export declare function util(arg: UtilInterface): void; +``` + +## validatePrimaryPackageOutputTarget + +*default: `false`* + +When `true`, validation for common `package.json` fields will occur based on setting an output target's `isPrimaryPackageOutputTarget` flag. +For more information on package validation, please see the [output target docs](../output-targets/01-overview.md#primary-package-output-target-validation). + +## rollupConfig + +Passes custom configuration down to rollup itself. The following options can be overwritten: + +- `inputOptions`: [`context`](https://rollupjs.org/configuration-options/#context), [`external`](https://rollupjs.org/configuration-options/#external), [`moduleContext`](https://rollupjs.org/configuration-options/#modulecontext) [`treeshake`](https://rollupjs.org/configuration-options/#treeshake) +- `outputOptions`: [`globals`](https://rollupjs.org/configuration-options/#output-globals) + +*default: `{}`* \ No newline at end of file diff --git a/versioned_docs/version-v4.19/config/_category_.json b/versioned_docs/version-v4.19/config/_category_.json new file mode 100644 index 000000000..b9de453d1 --- /dev/null +++ b/versioned_docs/version-v4.19/config/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Config", + "position": 5 +} diff --git a/versioned_docs/version-v4.19/config/cli.md b/versioned_docs/version-v4.19/config/cli.md new file mode 100644 index 000000000..5ea10a3a8 --- /dev/null +++ b/versioned_docs/version-v4.19/config/cli.md @@ -0,0 +1,107 @@ +--- +title: Stencil CLI +sidebar_label: CLI +description: Stencil CLI +slug: /cli +--- + +# Command Line Interface (CLI) + +Stencil's command line interface (CLI) is how developers can build their projects, run tests, and more. +Stencil's CLI is included in the compiler, and can be invoked with the `stencil` command in a project where `@stencil/core` is installed. + +## `stencil build` + +Builds a Stencil project. The flags below are the available options for the `build` command. + +| Flag | Description | Alias | +|------|-------------|-------| +| `--ci` | Run a build using recommended settings for a Continuous Integration (CI) environment. Defaults the number of workers to 4, allows for extra time if taking screenshots via the tests and modifies the console logs. | | +| `--config` | Path to the `stencil.config.ts` file. This flag is not needed in most cases since Stencil will find the config. Additionally, a Stencil config is not required. | `-c` | +| `--debug` | Adds additional runtime code to help debug, and sets the log level for more verbose output. | | +| `--dev` | Runs a development build. | | +| `--docs` | Generate all docs based on the component types, properties, methods, events, JSDocs, CSS Custom Properties, etc. | | +| `--es5` | Creates an ES5 compatible build. By default ES5 builds are not created during development in order to improve build times. However, ES5 builds are always created during production builds. Use this flag to create ES5 builds during development. | | +| `--log` | Write logs for the `stencil build` into `stencil-build.log`. The log file is written in the same location as the config. | | +| `--prerender` | Prerender the application using the `www` output target after the build has completed. | | +| `--prod` | Runs a production build which will optimize each file, improve bundling, remove unused code, minify, etc. A production build is the default, this flag is only used to override the `--dev` flag. | | +| `--max-workers` | Max number of workers the compiler should use. Defaults to use the same number of CPUs the Operating System has available. | | +| `--next` | Opt-in to test the "next" Stencil compiler features. | | +| `--no-cache` | Disables using the cache. | | +| `--no-open` | By default the `--serve` command will open a browser window. Using the `--no-open` command will not automatically open a browser window. | | +| `--port` | Port for the [Integrated Dev Server](./dev-server.md). Defaults to `3333`. | `-p` | +| `--serve` | Starts the [Integrated Dev Server](./dev-server.md). | | +| `--stats` | Write stats about the project to `stencil-stats.json`. The stats file is written in the same location as the config. | | +| `--verbose` | Logs additional information about each step of the build. | | +| `--watch` | Watches files during development and triggers a rebuild when files are updated. | | + +## `stencil docs` + +Performs a one-time generation of documentation for your project. +For more information on documentation generation, please see the [Documentation Generation section](../documentation-generation/01-overview.md). + +## `stencil generate` + +Alias: `stencil g` + +Starts the interactive generator for a new Stencil component. +The generator will ask you for a name for your component, and whether any stylesheets or testing files should be generated. + +If you wish to skip the interactive generator, a component tag name may be provided on the command line: +```shell +stencil generate my-new-component +``` + +All components will be generated within the `src/components` folder. +Within `src/components`, a directory will be created with the same name as the component tag name you provided containing the generated files. +For example, if you specify `page-home` as the component tag name, the files will be generated in `src/components/page-home`: +```plain +src +└── components + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +It is also possible to specify one or more sub-folders to generate the component in. +For example, if you specify `pages/page-home` as the component tag name, the files will be generated in `src/components/pages/page-home`: +```shell +stencil generate pages/page-home +``` +The command above will result in the following directory structure: +```plain +src +└── components + └── pages + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +## `stencil help` + +Aliases: `stencil --help`, `stencil -h` + +Prints various tasks that can be run and their associated flags to the terminal. + +## `stencil test` + +Tests a Stencil project. The flags below are the available options for the `test` command. + +| Flag | Description | +|------|-------------| +| `--spec` | Tests `.spec.ts` files using [Jest](https://jestjs.io/). | +| `--e2e` | Tests `.e2e.ts` files using [Puppeteer](https://developers.google.com/web/tools/puppeteer) and [Jest](https://jestjs.io/). | +| `--no-build` | Skips the build process before running end-to-end tests. When using this flag, it is assumed that your Stencil project has been built prior to running `stencil test`. Unit tests do not require this flag. | +| `--devtools` | Opens the dev tools panel in Chrome for end-to-end tests. Setting this flag will disable `--headless` | +| `--headless` | Sets the headless mode to use in Chrome for end-to-end tests. `--headless` and `--headless=true` will enable the "old" headless mode in Chrome, that was used by default prior to Chrome v112. `--headless=new` will enable the new headless mode introduced in Chrome v112. See [this article](https://developer.chrome.com/articles/new-headless/) for more information on Chrome's new headless mode. | + +## `stencil version` + +Aliases: `stencil -v`, `stencil --version` + +Prints the version of Stencil to the terminal. diff --git a/versioned_docs/version-v4.19/config/dev-server.md b/versioned_docs/version-v4.19/config/dev-server.md new file mode 100644 index 000000000..f83c55a05 --- /dev/null +++ b/versioned_docs/version-v4.19/config/dev-server.md @@ -0,0 +1,152 @@ +--- +title: Integrated Dev Server Config +sidebar_label: Dev Server +description: Integrated Dev Server Config +slug: /dev-server +--- + +# Integrated Dev Server + +Stencil comes with an integrated dev server in order to simplify development. By integrating the build process and the dev server, Stencil is able to drastically improve the development experience without requiring complicated build scripts and configuration. As app builds and re-builds take place, the compiler is able to communicate with the dev server, and vice versa. + +## Hot Module Replacement + +The compiler already provides a watch mode, but coupled with the dev server it's able to go one step farther by reloading only what has changed within the browser. Hot Module Replacement allows the app to keep its state within the browser, while switching out individual components with their updated logic after file saves. + +## Style Replacement + +Web components can come with their own css, can use shadow dom, and can have individual style tags. Traditionally, live-reload external css links usually does the trick, however, updating components with inline styles within shadow roots has been a challenge. With the integrated dev server, Stencil is able to dynamically update styles for all components, whether they're using shadow dom or not, without requiring a page refresh. + +## Development Errors + +When errors happen during development, such as printing an error for invalid syntax, Stencil will not only log the error and the source of the error in the console, but also overlay the app with the error so it's easier to read. + +## Open In Editor + +When a development error is shown and overlays the project within the browser, line numbers pointing to the source text are clickable, +which will open the source file directly in your IDE. + +## Dev Server Config + +### `address` + +**Optional** + +**Type: `string`** + +**Default: `0.0.0.0`** + +IP address used by the dev server. The default is `0.0.0.0`, which points to all IPv4 addresses on the local machine, such as `localhost`. + +### `basePath` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +Base path to be used by the server. Defaults to the root pathname. + +### `https` + +**Optional** + +**Type: `{ key: string; cert: string; } | false`** + +**Default: `false`** + +By default the dev server runs over the http protocol. Instead you can run it over https by providing your own SSL certificate and key (see example below). + +#### Example + +```tsx +import { readFileSync } from 'fs'; +import { Config } from '@stencil/core'; + +export const config: Config = { + devServer: { + reloadStrategy: 'pageReload', + port: 4444, + https: { + cert: readFileSync('cert.pem', 'utf8'), + key: readFileSync('key.pem', 'utf8'), + }, + }, +}; +``` + +### `initialLoadUrl` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +The URL the dev server should first open to. + +### `logRequests` + +**Optional** + +**Type: `boolean`** + +**Default: `false`** + +Every request to the server will be logged within the terminal. + +### `openBrowser` + +**Optional** + +**Type: `boolean`** + +**Default: `true`** + +By default, when dev server is started the local dev URL is opened in your default browser. However, to prevent this URL to be opened change this value to `false`. + +### `pingRoute` + +**Optional** + +**Type: `string | null`** + +**Default: `/ping`** + +Route to be registered on the dev server that will respond with a 200 OK response once the Stencil build has completed. The Stencil dev server will "spin up" +before the build process has completed, which can cause issues with processes that rely on the compiled and served output (like E2E testing). This route provides +a way for these processes to know when the build has finished and is ready to be accessed. + +If set to `null`, no route will be registered. + +### `port` + +**Optional** + +**Type: `number`** + +**Default: `3333`** + +Sets the server's port. + +### `reloadStrategy` + +**Optional** + +**Type: `'hmr' | 'pageReload' | null`** + +**Default: `hmr`** + +When files are watched and updated, by default the dev server will use `hmr` (Hot Module Replacement) to update the page without a full page refresh. +To have the page do a full refresh use `pageReload`. To disable any reloading, use `null`. + +### `root` + +**Optional** + +**Type: `string`** + +**Default: `www` output directory if exists, project root otherwise** + +The directory to serve files from. diff --git a/versioned_docs/version-v4.19/config/extras.md b/versioned_docs/version-v4.19/config/extras.md new file mode 100644 index 000000000..bfed8bfac --- /dev/null +++ b/versioned_docs/version-v4.19/config/extras.md @@ -0,0 +1,141 @@ +--- +title: Extras Config +sidebar_label: Extras +description: Extras Config +slug: /config-extras +--- + +# Extras + +The `extras` config contains options to enable new/experimental features in +Stencil, add & remove runtime for DOM features that require manipulations to +polyfills, etc. For example, not all DOM APIs are fully polyfilled when using +the Slot polyfill. Most of these are opt-in, since not all users require the +additional runtime. + +### appendChildSlotFix + +By default, the slot polyfill does not update `appendChild()` so that it appends new child nodes into the correct child slot like how shadow dom works. This is an opt-in polyfill for those who need it. + +### cloneNodeFix + +By default, the runtime does not polyfill `cloneNode()` when cloning a component that uses the slot polyfill. This is an opt-in polyfill for those who need it. + +### enableImportInjection + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +Enabling this flag will allow downstream projects that consume a Stencil library and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalImportInjection + +:::caution +This flag has been deprecated in favor of [`enableImportInjection`](#enableimportinjection), which provides the same +functionality. `experimentalImportInjection` will be removed in a future major version of Stencil. +::: + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +This is an experimental flag that, when set to `true`, will allow downstream projects that consume a Stencil library +and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalScopedSlotChanges + +This option updates runtime behavior for Stencil's support of slots in **scoped** components to match more closely with +the native Shadow DOM behaviors. + +When set to `true`, the following behaviors will be applied: + +- Stencil will hide projected nodes that do not have a destination `slot` ([#2778](https://github.com/ionic-team/stencil/issues/2877)) (since v4.10.0) +- The `textContent` getter will return the text content of all nodes located in a slot (since v4.10.0) +- The `textContent` setter will overwrite all nodes located in a slot (since v4.10.0) + +Defaults to `false`. + +:::note +These behaviors only apply to components using scoped encapsulation! +::: + +### experimentalSlotFixes + +This option enables all current and future slot-related fixes. When enabled it +will enable the following options, overriding their values if they are +specified separately: + +- [`slotChildNodesFix`](#slotchildnodesfix) +- [`scopedSlotTextContentFix`](#scopedslottextcontentfix). +- [`appendChildSlotFix`](#appendchildslotfix) +- [`cloneNodeFix`](#clonenodefix) + +Slot-related fixes to the runtime will be added over the course of Stencil v4, +with the intent of making these the default behavior in Stencil v5. When set to +`true` fixes for the following issues will be applied: + +- Elements rendered outside of slot when shadow not enabled [(#2641)](https://github.com/ionic-team/stencil/issues/2641) (since v4.2.0) +- A slot gets the attribute hidden when it shouldn't [(#4523)](https://github.com/ionic-team/stencil/issues/4523) (since v4.7.0) +- Nested slots mis-ordered when not using Shadow DOM [(#2997)](https://github.com/ionic-team/stencil/issues/2997) (since v4.7.0) +- Inconsistent behavior: slot-fb breaks styling of default slot content in component with 'shadow: false' [(#2937)](https://github.com/ionic-team/stencil/issues/2937) (since v4.7.2) +- Slot content went missing within dynamic component [(#4284)](https://github.com/ionic-team/stencil/issues/4284) (since v4.8.2) +- Slot element loses its parent reference and disappears when its parent is rendered conditionally [(#3913)](https://github.com/ionic-team/stencil/issues/3913) (since v4.8.2) +- Failed to execute 'removeChild' on 'Node' [(#3278)](https://github.com/ionic-team/stencil/issues/3278) (since v4.9.0) +- React fails to manage children in Stencil slot [(#2259)](https://github.com/ionic-team/stencil/issues/2259) (since v4.9.0) +- Slot name is not updated when it is bind to a prop [(#2982)](https://github.com/ionic-team/stencil/issues/2982) (since 4.12.1) +- Conditionally rendered slots not working [(#5335)](https://github.com/ionic-team/stencil/issues/5335) (since 4.13.0) + +:::note +New fixes enabled by this experimental flag are not subject to Stencil's +[semantic versioning policy](../reference/versioning.md). +::: + +### lifecycleDOMEvents + +Dispatches component lifecycle events. By default these events are not dispatched, but by enabling this to `true` these events can be listened for on `window`. Mainly used for testing. + +| Event Name | Description | +| ----------------------------- | ------------------------------------------------------ | +| `stencil_componentWillLoad` | Dispatched for each component's `componentWillLoad`. | +| `stencil_componentWillUpdate` | Dispatched for each component's `componentWillUpdate`. | +| `stencil_componentWillRender` | Dispatched for each component's `componentWillRender`. | +| `stencil_componentDidLoad` | Dispatched for each component's `componentDidLoad`. | +| `stencil_componentDidUpdate` | Dispatched for each component's `componentDidUpdate`. | +| `stencil_componentDidRender` | Dispatched for each component's `componentDidRender`. | + +### scopedSlotTextContentFix + +An experimental flag that when set to `true`, aligns the behavior of invoking the `textContent` getter/setter on a scoped component to act more like a component that uses the shadow DOM. Specifically, invoking `textContent` on a component will adhere to the return values described in [MDN's article on textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#description). Defaults to `false`. + +### scriptDataOpts + +:::caution +This option has been deprecated and will be removed in the next major Stencil release. +::: + +It is possible to assign data to the actual ` + + + + + +``` + +Alternatively, if you wanted to take advantage of ES Modules, you could include the components using an import statement. + +```markup + + + + + + + + +``` + +## Passing object props from a non-JSX element + +### Setting the prop manually + +```tsx +import { Prop } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: object; + @Prop() myArray: Array; +} +``` + +```markup + + +``` + +### Watching props changes + +```tsx +import { Prop, State, Watch } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: string; + @Prop() myArray: string; + @State() myInnerObject: object; + @State() myInnerArray: Array; + + componentWillLoad() { + this.parseMyObjectProp(this.myObject); + this.parseMyArrayProp(this.myArray); + } + + @Watch('myObject') + parseMyObjectProp(newValue: string) { + if (newValue) this.myInnerObject = JSON.parse(newValue); + } + + @Watch('myArray') + parseMyArrayProp(newValue: string) { + if (newValue) this.myInnerArray = JSON.parse(newValue); + } +} +``` + +```tsx + +``` diff --git a/versioned_docs/version-v4.19/framework-integration/react.md b/versioned_docs/version-v4.19/framework-integration/react.md new file mode 100644 index 000000000..973272942 --- /dev/null +++ b/versioned_docs/version-v4.19/framework-integration/react.md @@ -0,0 +1,505 @@ +--- +title: React Integration with Stencil +sidebar_label: React +description: Learn how to wrap your components so that people can use them natively in React +slug: /react +--- + +# React Integration + +**Supports: React v16.7+ • TypeScript 3.7+ • Stencil v2.9.0+** + +Stencil can generate React component wrappers for your web components. This allows your Stencil components to be used within +a React application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Custom events will be handled correctly and correctly propagate through the React render tree +- Properties and attributes that are not a string or number will be correctly bound to the component + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component +wrappers. Your project workspace should contain your Stencil component library and the library for the generated React component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── stencil-library/ + │ ├── stencil.config.js + │ └── src/components/ + └── react-library/ + └── src/ + ├── components/ + └── index.ts +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +From the `packages/` directory, run the following commands to create a Stencil component library: + +```bash npm2yarn +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a React Component Library + +:::note +If you already have a React component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a React library package to write to. + +Run the following commands from the root directory of your monorepo to create a React component library: + +```bash npm2yarn +# Create a project +lerna create react-library # fill out the prompts accordingly +cd packages/react-library + +# Install core dependencies +npm install react react-dom typescript @types/react --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `react-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2015"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2015", + "skipLibCheck": true, + "jsx": "react", + "allowSyntheticDefaultImports": true, + "declarationDir": "./dist/types" + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `react-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/react-library.js", ++ "main": "dist/index.js", ++ "module": "dist/index.js", ++ "types": "dist/types/index.d.ts", + "scripts": { +- "test": "node ./__tests__/react-library.test.js" ++ "test": "node ./__tests__/react-library.test.js", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, + "files": [ +- "lib" ++ "dist" + ], ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the React Output Target + +Install the `@stencil/react-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency +npm install @stencil/react-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `reactOutputTarget` configuration to the `outputTargets` array: + +```ts +import { reactOutputTarget } from '@stencil/react-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // React target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + reactOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../react-library/lib/components/stencil-generated/index.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all of the React component wrappers. You will replace the +file path to match your project's structure and respective names. You can generate any file name instead of `index.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +See the [API section below](#api) for details on each of the output target's options. + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers +npm run build +``` + +If the build is successful, you’ll see the new generated file in your React component library at the location specified by the `proxiesFile` argument. + +### Add the Components to your React Component Library's Entry File + +In order to make the generated files available within your React component library and its consumers, you’ll need to export everything from within your entry file. First, rename `react-library.js` to `index.ts`. Then, modify the contents to match the following: + +```tsx +export * from './components/stencil-generated'; +``` + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you'll need to expose a method for registering the underlying Stencil +generated custom elements for the React proxy components to leverage. The easiest way to do this is to modify the React library's entry file +to re-export the Stencil loader's `defineCustomElements()` method. In your React library's entry file (`packages/react-library/lib/index.ts`), +add the following: + +```diff +export * from "./components/stencil-generated"; ++ export { defineCustomElements } from "stencil-library/loader"; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your React component library, you will need to link the Stencil package to the React package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your React component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the React component library. + +:::tip +As an alternative to `npm link` , you can also run `npm install` with a relative path to your Stencil component library. This strategy, however, will +modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer React App + +:::note +If you already have a React app, skip this section. +::: + +From the `packages/` directory, run the following commands to create a starter React app: + + + + +```bash +# Create the React app +npm create vite@latest my-app -- --template react-ts +# of if using yarn +yarn create vite my-app --template react-ts + +cd ./my-app + +# install dependencies +npm install +# or if using yarn +yarn install +``` + +You'll also need to link your React component library as a dependency. This step makes it so your React app will be able to correctly resolve imports from your React library. This +is easily done by modifying your React app's `package.json` to include the following: + +```json +"dependencies": { + "react-library": "*" +} +``` + +### Consuming the React Wrapper Components + +This section covers how developers consuming your React component wrappers will use your package and component wrappers. + +Before you can consume your React proxy components, you'll need to build your React component library. From `packages/react-library` run: + +```bash npm2yarn +npm run build +``` + +To make use of your React component library in your React application, import your components from your React component library in the file where you want to use them. + +```tsx +// App.tsx +import './App.css'; +import { MyComponent, defineCustomElements } from 'react-library'; + +defineCustomElements(); + +function App() { + return ( +
    + +
    + ); +} + +export default App; +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + reactOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate React wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with React Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements](../output-targets/custom-elements.md) output and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your React project. + +## FAQ's + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + reactOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the React output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the React application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the React component library. + +### What is the best format to write event names? + +Event names shouldn’t include special characters when initially written in Stencil. Try to lean on using camelCased event names for interoperability between frameworks. diff --git a/versioned_docs/version-v4.19/framework-integration/vue.md b/versioned_docs/version-v4.19/framework-integration/vue.md new file mode 100644 index 000000000..143a858a8 --- /dev/null +++ b/versioned_docs/version-v4.19/framework-integration/vue.md @@ -0,0 +1,673 @@ +--- +title: VueJS Integration with Stencil +sidebar_label: Vue +description: Learn how to wrap your components so that people can use them natively in Vue +slug: /vue +--- + +# Vue Integration + +**Supports: Vue 3 • TypeScript 4.0+ • Stencil v2.9.0+** + +Stencil can generate Vue component wrappers for your web components. This allows your Stencil components to be used within a Vue 3 application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Type checking with your components. +- Integration with the router link and Vue router. +- Optionally, form control web components can be used with `v-model`. + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component wrappers. Your project workspace should contain your Stencil component library and the library for the generate Vue component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── vue-library/ + │ └── lib/ + │ ├── plugin.ts + │ └── index.ts + └── stencil-library/ + ├── stencil.config.js + └── src/components +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +```bash npm2yarn +cd packages/ +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a Vue Component Library + +:::note +If you already have a Vue component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a Vue library package to write to. + +Using Lerna and Vue's CLI, generate a workspace and a library for your Vue component wrappers: + +```bash npm2yarn +# From your top-most-directory/ +lerna create vue-library +# Follow the prompts and confirm +cd packages/vue-library +# Install Vue dependency +npm install vue@3 --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `vue-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2020"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2017", + "skipLibCheck": true + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `vue-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/vue-library.js", ++ "main": "dist/index.js", ++ "types": "dist/index.d.ts", + "files": [ +- 'lib' ++ 'dist' + ], + "scripts": { +- "test": "echo \"Error: run tests from root\" && exit 1" ++ "test": "echo \"Error: run tests from root\" && exit 1", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the Vue Output Target + +Install the `@stencil/vue-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency (from `packages/stencil-library`) +npm install @stencil/vue-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `vueOutputTarget` configuration to the `outputTargets` array: + +```ts +import { vueOutputTarget } from '@stencil/vue-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // Vue target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + vueOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../vue-library/lib/components.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all the Vue component wrappers. You will replace the file path to match +your project's structure and respective names. You can generate any file name instead of `components.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers (from `packages/stencil-library`) +npm run build +``` + +If the build is successful, you will now have contents in the file specified in `proxiesFile`. + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you will need to create a new file for the Vue plugin: + +```ts +// packages/vue-library/lib/plugin.ts + +import { Plugin } from 'vue'; +import { applyPolyfills, defineCustomElements } from 'stencil-library/loader'; + +export const ComponentLibrary: Plugin = { + async install() { + applyPolyfills().then(() => { + defineCustomElements(); + }); + }, +}; +``` + +You can now finally export the generated component wrappers and the Vue plugin for your component library to make them available to implementers. Export +the `plugin.ts` file created in the previous step, as well as the file `proxiesFile` generated by the Vue Output Target: + +```ts +// packages/vue-library/lib/index.ts +export * from './components'; +export * from './plugin'; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your Vue component library, you will need to link the Stencil package to the Vue package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your Vue component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the Vue component library. + +:::note +As an alternative to `npm link`, you can also run `npm install` with a relative path to your Stencil component library. This strategy, +however, will modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer Vue App + +From the `packages/` directory, run the following command to generate a Vue app: + +```bash npm2yarn +npm init vue@3 my-app +``` + +Follow the prompts and choose the options best for your project. + +You'll also need to link your Vue component library as a dependency. This step makes it so your Vue app will be able to correctly +resolve imports from your Vue library. This is easily done by modifying your Vue app's `package.json` to include the following: + +```json +"dependencies": { + "vue-library": "*" +} +``` + +For more information, see the Lerna documentation on [package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management). + +Lastly, you'll want to update the generated `vite.config.ts`: + +```diff +export default defineConfig({ +- plugins: [vue(), vueJsx()], ++ plugins: [ ++ vue({ ++ template: { ++ compilerOptions: { ++ // treat all tags with a dash as custom elements ++ isCustomElement: (tag) => tag.includes('-'), ++ }, ++ }, ++ }), ++ vueJsx(), ++ ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } +}) +``` + +This will prevent Vue from logging a warning about failing to resolve components (e.g. "Failed to resolve component: my-component"). + +### Consuming the Vue Wrapper Components + +This section covers how developers consuming your Vue component wrappers will use your package and component wrappers. + +Before you can use your Vue proxy components, you'll need to build your Vue component library. From `packages/vue-library` simply run: + +```bash npm2yarn +npm run build +``` + +In your `main.js` file, import your component library plugin and use it: + +```js +// src/main.js +import { ComponentLibrary } from 'vue-library'; + +createApp(App).use(ComponentLibrary).mount('#app'); +``` + +In your page or component, you can now import and use your component wrappers: + +```html + +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### componentModels + +**Optional** + +**Default: `[]`** + +**Type: `ComponentModelConfig[]`** + +This option is used to define which components should be integrated with `v-model`. It allows you to set what the target prop is (i.e. `value`), +which event will cause the target prop to change, and more. + +```tsx +const componentModels: ComponentModelConfig[] = [ + { + elements: ['my-input', 'my-textarea'], + event: 'v-on-change', + externalEvent: 'on-change', + targetAttr: 'value', + }, +]; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + componentModels: componentModels, + }), + ], +}; +``` + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate Vue wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with Vue's Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements Bundle](../output-targets/custom-elements.md) and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your Vue project. + +## FAQ + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the Vue output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the Vue application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the Vue component library. + +### Vue warns "Failed to resolve component: my-component" + +#### Lazy loaded bundle + +If you are using Vue CLI, update your `vue.config.js` to match your custom element selector as a custom element: + +```js +const { defineConfig } = require('@vue/cli-service'); +module.exports = defineConfig({ + transpileDependencies: true, + chainWebpack: (config) => { + config.module + .rule('vue') + .use('vue-loader') + .tap((options) => { + options.compilerOptions = { + ...options.compilerOptions, + // The stencil-library components start with "my-" + isCustomElement: (tag) => tag.startsWith('my-'), + }; + return options; + }); + }, +}); +``` + +#### Custom elements bundle + +If you see this warning, then it is likely you did not import your component from your Vue library: `vue-library`. By default, all Vue components are locally registered, meaning you need to import them each time you want to use them. + +Without importing the component, you will only get the underlying Web Component, and Vue-specific features such as `v-model` will not work. + +To resolve this issue, you need to import the component from `vue-library` (your package name) and provide it to your Vue component: + +```html + + + +``` + +### Vue warns: "slot attributes are deprecated vue/no-deprecated-slot-attribute" + +The slots that are used in Stencil are [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots) slots, which are different than the slots used in Vue 2. Unfortunately, the APIs for both are very similar, and your linter is likely getting the two confused. + +You will need to update your lint rules in `.eslintrc.js` to ignore this warning: + +```js +module.exports = { + rules: { + 'vue/no-deprecated-slot-attribute': 'off', + }, +}; +``` + +If you are using VSCode and have the Vetur plugin installed, you are likely getting this warning because of Vetur, not ESLint. By default, Vetur loads the default Vue 3 linting rules and ignores any custom ESLint rules. + +To resolve this issue, you will need to turn off Vetur's template validation with `vetur.validation.template: false`. See the [Vetur Linting Guide](https://vuejs.github.io/vetur/guide/linting-error.html#linting) for more information. + +### Method on component is not a function + +In order to access a method on a Stencil component in Vue, you will need to access the underlying Web Component instance first: + +```ts +// ✅ This is correct +myComponentRef.value.$el.someMethod(); + +// ❌ This is incorrect and will result in an error. +myComponentRef.value.someMethod(); +``` + +### Output commonjs bundle for Node environments + +First, install `rollup` and `rimraf` as dev dependencies: + +```bash npm2yarn +npm i -D rollup rimraf +``` + +Next, create a `rollup.config.js` in `/packages/vue-library/`: + +```js +const external = ['vue', 'vue-router']; + +export default { + input: 'dist-transpiled/index.js', + output: [ + { + dir: 'dist/', + entryFileNames: '[name].esm.js', + chunkFileNames: '[name]-[hash].esm.js', + format: 'es', + sourcemap: true, + }, + { + dir: 'dist/', + format: 'commonjs', + preferConst: true, + sourcemap: true, + }, + ], + external: (id) => external.includes(id) || id.startsWith('stencil-library'), +}; +``` + +:::info +Update the `external` list for any external dependencies. Update the `stencil-library` to match your Stencil library's package name. +::: + +Next, update your `package.json` to include the scripts for rollup: + +```json +{ + "scripts": { + "build": "npm run clean && npm run tsc && npm run bundle", + "bundle": "rollup --config rollup.config.js", + "clean": "rimraf dist dist-transpiled" + } +} +``` diff --git a/versioned_docs/version-v4.19/guides/_category_.json b/versioned_docs/version-v4.19/guides/_category_.json new file mode 100644 index 000000000..afdb49ff4 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Guides", + "position": 8 +} diff --git a/versioned_docs/version-v4.19/guides/assets.md b/versioned_docs/version-v4.19/guides/assets.md new file mode 100644 index 000000000..f6dda9fce --- /dev/null +++ b/versioned_docs/version-v4.19/guides/assets.md @@ -0,0 +1,284 @@ +--- +title: Assets +sidebar_label: Assets +description: Learn how to reference assets in your components +slug: /assets +--- + +# Assets + +Stencil components may need one or more static files as a part of their design. +These types of files are referred to as 'assets', and include images, fonts, etc. + +In this guide, we describe different strategies for resolving assets on the filesystem. + +:::note +CSS files are handled differently than assets; for more on using CSS, please see the [styling documentation](../components/styling.md). +::: + +## Asset Base Path + +The **asset base path** is the directory that Stencil will use to resolve assets. +When a component uses an asset, the asset's location is resolved relative to the asset base path. + +The asset base path is automatically set for the following output targets: +- [dist](../output-targets/dist.md) +- [hydrate](./hydrate-app.md) +- [www](../output-targets/www.md) + +For all other output targets, assets must be [moved](#manually-moving-assets) and the asset base path must be [manually set](#setassetpath). + +For each instance of the Stencil runtime that is loaded, there is a single asset base path. +Oftentimes, this means there is only one asset base path per application using Stencil. + +## Resolution Overview + +The process of resolving an asset involves asking Stencil to build a path to the asset on the filesystem. + +When an asset's path is built, the resolution is always done in a project's compiled output, not the directory containing the original source code. + +The example below uses the output of the [`www` output target](../output-targets/www.md) to demonstrate how assets are resolved. +Although the example uses the output of `www` builds, the general principle of how an asset is found holds for all output targets. + +When using the `www` output target, a `build/` directory is automatically created and set as the asset base path. +An example `build/` directory and the assets it contains can be found below. + +``` +www/ +├── build/ +│ ├── assets/ +│ │ ├── logo.png +│ │ └── scenery/ +│ │ ├── beach.png +│ │ └── sunset.png +│ └── other-assets/ +│ └── font.tiff +└── ... +``` + +To resolve the path to an asset, Stencil's [`getAssetPath()` API](#getassetpath) may be used. +When using `getAssetPath`, the assets in the directory structure above are resolved relative to `build/`. + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments. +The return value is a path that Stencil has built to retrieve the asset on the filesystem. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": + +// '/build/assets/logo.png' +getAssetPath('assets/logo.png'); +// '/build/assets/scenery/beach.png' +getAssetPath('assets/scenery/beach.png'); +// '/build/other-assets/font.tiff' +getAssetPath('other-assets/font.tiff'); +``` + +## Making Assets Available + +In order to be able to find assets at runtime, they need to be found on the filesystem from the output of a Stencil build. +In other words, we need to ensure they exist in the distribution directory. +This section describes how to make assets available under the asset base path. + +### assetsDirs + +The `@Component` decorator can be [configured with the `assetsDirs` option](../components/component.md#component-options). +`assetsDirs` takes an array of strings, where each entry is a relative path from the component to a directory containing the assets the component requires. + +When using the `dist` or `www` output targets, setting `assetsDirs` instructs Stencil to copy that folder into the distribution folder. +When using other output targets, Stencil will not copy assets into the distribution folder. + +Below is an example project's directory structure containing an example component and an assets directory. + +``` +src/ +└── components/ + ├── assets/ + │ ├── beach.jpg + │ └── sunset.jpg + └── my-component.tsx +``` + +Below, the `my-component` component will correctly load the assets based on it's `image` prop. + +```tsx +// file: my-component.tsx +// 1. getAssetPath is imported from '@stencil/core' +import { Component, Prop, getAssetPath, h } from '@stencil/core'; + +@Component({ + tag: 'my-component', + // 2. assetsDirs lists the 'assets' directory as a relative + // (sibling) directory + assetsDirs: ['assets'] +}) +export class MyComponent { + + @Prop() image = "sunset.jpg"; + + render() { + // 3. the asset path is retrieved relative to the asset + // base path to use in the tag + const imageSrc = getAssetPath(`./assets/${this.image}`); + return + } +} +``` + +In the example above, the following allows `my-component` to display the provided asset: +1. [`getAssetPath()`](#getassetpath) is imported from `@stencil/core` +2. The `my-component`'s component decorator has the `assetsDirs` property, and lists the sibling directory, `assets`. This will copy `assets` over to the distribution directory. +3. `getAssetPath` is used to retrieve the path to the image to be used in the `` tag + +### Manually Moving Assets + +For the [dist-custom-elements](../output-targets/custom-elements.md) output target, options like `assetsDirs` do not copy assets to the distribution directory. + +It's recommended that a bundler (such as rollup) or a Stencil `copy` task is used to ensure the static assets are copied to the distribution directory. + +#### Stencil Copy Task + +[Stencil `copy` task](../output-targets/copy-tasks.md)s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a copy task can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```ts +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'your-component-library', + outputTargets: [ + { + type: 'dist-custom-elements', + copy: [ + { + src: '**/*.{jpg,png}', + dest: 'dist/components/assets', + warn: true, + } + ] + }, + ], + // ... +}; +``` +#### Rollup Configuration + +[Rollup Plugins](../config/plugins.md#rollup-plugins)'s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a the `rollup-plugin-copy` NPM module can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```javascript +import { Config } from '@stencil/core'; +import copy from 'rollup-plugin-copy'; + +export const config: Config = { + namespace: 'copy', + outputTargets: [ + { + type: 'dist-custom-elements', + }, + ], + rollupPlugins: { + after: [ + copy({ + targets: [ + { + src: 'src/**/*.{jpg,png}', + dest: 'dist/components/assets', + }, + ], + }), + ] + } +}; +``` + +## API Reference + +### getAssetPath + +`getAssetPath()` is an API provided by Stencil to build the path to an asset, relative to the asset base path. + +```ts +/** + * Builds a URL to an asset. This is achieved by combining the + * provided `path` argument with the base asset path. + * @param path the path of the asset to build a URL to + * @returns the built URL + */ +declare function getAssetPath(path: string): string; +``` + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments, when an asset base path of `/build/` has been set. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": +// "/build/" +getAssetPath(''); +// "/build/my-image.png" +getAssetPath('my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('assets/my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('./assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('../assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('/assets/my-image.png'); +``` + +### setAssetPath + +`setAssetPath` is an API provided by Stencil's runtime to manually set the asset base path where assets can be found. If you are using `getAssetPath` to compose the path for your component assets, `setAssetPath` allows you or the consumer of the component to change that path. + +```ts +/** + * Set the base asset path for resolving components + * @param path the base asset path + * @returns the new base asset path + */ +export declare function setAssetPath(path: string): string; +``` + +Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects when using a component. + +Make sure as component author to export this function as part of your module in order to also make it accessible to the consumer of your component, e.g. in your package entry file export the function via: + +```ts title="/src/index.ts" +export { setAssetPath } from '@stencil/core'; +``` + +Now your users can import it directly from your component library, e.g.: + +```ts +import { setAssetPath } from 'my-component-library'; +setAssetPath(`${window.location.protocol}//assets.${window.location.host}/`); +``` + +Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the +asset base path. This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. + +:::note + +If your component library exports components compiled with [`dist-output-target`](/output-targets/custom-elements.md) and `externalRuntime` set to `true`, then `setAssetPath` has to be imported from `@stencil/core` directly. + +::: + +In case you import a component directly via script tag, this would look like: + +```html + + + + + + + + + +``` diff --git a/versioned_docs/version-v4.19/guides/build-conditionals.md b/versioned_docs/version-v4.19/guides/build-conditionals.md new file mode 100644 index 000000000..0f540e8de --- /dev/null +++ b/versioned_docs/version-v4.19/guides/build-conditionals.md @@ -0,0 +1,41 @@ +--- +title: Build Conditionals +description: Build Conditionals +--- + +# Build Conditionals + +Build Conditionals in Stencil allow you to run specific code only when Stencil is running in development mode. This code is stripped from your bundles when doing a production build, therefore keeping your bundles as small as possible. + +### Using Build Conditionals + +Lets dive in and look at an example of how to use our build conditional: + +```tsx +import { Component, Build } from '@stencil/core'; + +@Component({ + tag: 'stencil-app', + styleUrl: 'stencil-app.css' +}) +export class StencilApp { + + componentDidLoad() { + if (Build.isDev) { + console.log('im in dev mode'); + } else { + console.log('im running in production'); + } + } +} +``` + +As you can see from this example, we just need to import `Build` from `@stencil/core` and then we can use the `isDev` constant to detect when we are running in dev mode or production mode. + +### Use Cases + +Some use cases we have come up with are: + +- Diagnostics code that runs in dev to make sure logic is working like you would expect +- `console.log()`'s that may be useful for debugging in dev mode but that you don't want to ship +- Disabling auth checks when in dev mode diff --git a/versioned_docs/version-v4.19/guides/csp-nonce.md b/versioned_docs/version-v4.19/guides/csp-nonce.md new file mode 100644 index 000000000..e18636cd8 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/csp-nonce.md @@ -0,0 +1,119 @@ +--- +title: Content Security Policy Nonces +description: How to leverage CSP nonces in Stencil projects. +slug: /csp-nonce +--- + +# Using Content Security Policy Nonces in Stencil + +[Content Security Policies (CSPs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) can help protect an application from Cross-Site Scripting (XSS) +attacks by adding a security layer to help prevent unauthorized code from running in the browser. + +An application that is served with a CSP other than 'unsafe-inline' and contains web components without a Shadow DOM will likely run into errors on load. +This is often first detected in the browser's console, which reports an error stating that certain styles or scripts violate the effective CSP. + +To resolve this issue, Stencil supports using [CSP nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) in +many of the output targets. + +:::caution +NOTE: CSPs and some CSP strategies are not supported by certain browsers. For a more detailed list, please see the [CSP browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#browser_compatibility). +::: + +## How to Use a Nonce + +The actual generation of the nonce value and enforcement of the correct CSP are not the responsibility of Stencil. Instead, the server of +the application will need to generate the nonce value for each page view, construct the CSP, and then correctly handle passing the generated nonce to +Stencil based on which output target is being consumed. + +There are many resources available that walk through setting up a CSP and using the nonce behavior. +[This](https://towardsdatascience.com/content-security-policy-how-to-create-an-iron-clad-nonce-based-csp3-policy-with-webpack-and-nginx-ce5a4605db90) +article walks through the process using Nginx and Webpack. Obviously, these resources don't account for the Stencil specifics, but any specifics will +be called out in this guide. + +Per the [MDN Guide on nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce#generating_values), a nonce should be "a random base64-encoded string of at least 128 bits of data from a cryptographically secure random number generator". + +### Output Targets + +Using nonces may differ slightly between output targets, so please be sure to use the correct pattern based on the context in which your +Stencil components are consumed. + +#### Dist + +Consuming a `nonce` in the `dist` output target is easy using the provided `setNonce` helper function. This function is exported from the index +file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); + +defineCustomElements(); +``` + +#### Custom Elements + +Consuming a `nonce` in the `dist-custom-elements` output target is easy using the provided `setNonce` helper function. This function is exported +from the index file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist-custom-elements` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/dist/components'; +// Assume `customElementsExportBehavior: 'auto-define-custom-elements'` is set +import 'my-lib/dist/components/my-component'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); +``` + +#### WWW + +Unfortunately, setting `nonce` attributes gets a bit trickier when it comes to [SSR and SSG](../static-site-generation/01-overview.md). As a `nonce` needs +to be unique per page view, it cannot be defined/set at build time. So, this responsibility now falls on the +[hydrate app](../guides/hydrate-app.md)'s execution of runtime code. + +**SSR** + +Since there is not an easy way (or any way) of exposing and executing helper functions to manipulate the outcome of the runtime code, Stencil +has fallback behavior for pulling the `nonce` off of a `meta` tag in the DOM head. + +So, for SSR, your app can simply inject a `meta` element into the header _on each page request_. Yes, this does involve some manual configuration +for the code served by your server. To work correctly, the created tag must be generated as follows: + +```html + +``` + +This isn't a security risk because, for an attacker to execute a script to pull the nonce from the meta tag, they would have needed to know the +nonce _ahead_ of the script's execution. + +**SSG** + +Stencil cannot support CSP nonces with SSG. Because all of the code is generated during [pre-rendering](../static-site-generation/01-overview.md#how-static-site-generation-and-prerendering-works), Stencil doesn't generate the `style` or `script` tags at runtime. +If an application wants to leverage nonces in SSG, they can build a mechanism to scrape the pre-rendered code and apply the attribute server-side before +it is served to the client. diff --git a/versioned_docs/version-v4.19/guides/design-systems.md b/versioned_docs/version-v4.19/guides/design-systems.md new file mode 100644 index 000000000..356f9dcbc --- /dev/null +++ b/versioned_docs/version-v4.19/guides/design-systems.md @@ -0,0 +1,77 @@ +--- +title: Design Systems +sidebar_label: Design Systems +description: Design Systems in Stencil +slug: /design-systems +--- + +# Design Systems + +## What is a Design System? + +A Design System consists of UI components and a clearly defined visual style, released as both code implementations and design artifacts. +When adopted by all product teams, a more cohesive customer experience emerges. + +There are several aspects that Design Systems consist of: + +### Components +A component is a standalone UI element designed to be reusable across many projects. +Its goal is to do one thing well, while remaining abstract enough to allow for a variety of use cases. +Developers can use them as building blocks to build new user experiences. +One of the key benefits of reusable components is that developers don't have to worry about the core design and functionality of each component every time they use them. +Examples include buttons, links, forms, input fields, and modals. + +### Patterns +A pattern is an opinionated use of components. +Often, multiple components are combined in order to create a standardized user experience (UX). +As a result, they improve both the user and developer experience. +After implementing patterns, users will understand the application better and accomplish their tasks faster. +When the development team understands the proper way to use components together, software applications become easier to use. +Examples include saving data to the system, capturing data from forms, and filtering and analyzing data. + +### Visual Language +A cohesive company brand strengthens its value in the minds of the customer. +In the context of design systems, this means defining various aspects of the visual style, including colors, typography, and icons. +Defining primary, secondary, and tertiary colors helps an application stand out and is more user-friendly. +The right typography ensures users are not distracted while using an app. +Finally, icons increase engagement in a product and make it “pop” visually. + +### Design Artifacts and Code Implementations +By leveraging the components, patterns, and visual language of the design system, designers can create design artifacts representing UI workflows. +Developers refer to the artifacts as guidance for implementing the design with code. + +## The Value of Design Systems +With a design system in place, its true value is revealed. +The entire product development team is freed up to focus on what matters most: solving customer problems and delivering value. +Additionally, the avoidance of having teams working in parallel, recreating the same UI elements over and over, has a real-world project impact in terms of reduced time to market and increased cost savings. + +Design systems allow project teams to work better together. +Designers define a centralized “source of truth” for software application best practices which can be referenced by anyone in a product organization. +Developers no longer need to spend time rethinking how to build common app scenarios, such as application search or data table grids. +When the business inevitably makes changes to the design system, they can easily be applied to all projects. +The end result is a better product for your users. + +## Using Stencil to Build a Design System + +There’s a lot that goes into creating amazing UI components. +Performance, accessibility, cross-platform capabilities, and user experience (not only of the UI component itself but how it fits into the entire design system) all must be considered. + +These aspects take real effort to do well. + +Enter Stencil, a robust and highly extensible tool for building components and patterns, the building blocks of a design system. +With its intentionally minimalistic tooling and API footprint, it’s simple to incorporate into your existing development workflows. +It brings substantial performance out of the box by leveraging a tiny runtime. +Most importantly, all UI components built with Stencil are based 100% on open web standards. + +### The Importance of Open Web Standards +By using the web components standard, supported in all modern browsers, Stencil-built UI components offer many distinct advantages for use in a design system, namely: + +* They work on any platform or device +* They work with any front-end framework, so they can easily be used across teams and projects using different tech stacks +* They facilitate the creation of one company-wide code implementation instead of one per framework or platform + +Learn more about why web components are ideal for design systems in [this blog post](https://blog.ionicframework.com/5-reasons-web-components-are-perfect-for-design-systems/). + +### How to Get Started +Stencil’s out-the-box features will help you build your own library of universal UI components that will work across platforms, devices, and front-end frameworks. +Review the documentation on this site to get started. diff --git a/versioned_docs/version-v4.19/guides/forms.md b/versioned_docs/version-v4.19/guides/forms.md new file mode 100644 index 000000000..555162b98 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/forms.md @@ -0,0 +1,165 @@ +--- +title: Forms +sidebar_label: Forms +description: Forms +slug: /forms +--- + +# Forms + +## Basic forms + +Here is an example of a component with a basic form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + + @State() value: string; + + handleSubmit(e) { + e.preventDefault() + console.log(this.value); + // send data to our backend + } + + handleChange(event) { + this.value = event.target.value; + } + + render() { + return ( +
    this.handleSubmit(e)}> + + +
    + ); + } +} +``` + +Let's go over what is happening here. First we bind the value of the input to a state variable, in this case `this.value`. We then set our state variable to the new value of the input with the `handleChange` method we have bound to `onInput`. `onInput` will fire every keystroke that the user types into the input. + +## Using form-associated custom elements + +In addition to using a `
    ` element inside of a Stencil component, as shown +in the above example, you can also use Stencil's support for building +form-associated custom elements to create a Stencil component that integrates +in a native-like way with a `` tag _around_ it. This allows you to build +rich form experiences using Stencil components which leverage built-in form +features like validation and accessibility. + +As an example, translating the above example to be a form-associated component +(instead of one which includes a `` element in its JSX) would look like +this: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css', + formAssociated: true +}) +export class MyName { + @State() value: string; + @AttachInternals() internals: ElementInternals; + + handleChange(event) { + this.internals.setFormValue(event.target.value); + } + + render() { + return ( + + ); + } +} +``` + +For more check out the docs for [form-association in Stencil](../components/form-associated.md). + +## Advanced forms + +Here is an example of a component with a more advanced form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + selectedReceiverIds = [102, 103]; + @State() value: string; + @State() selectValue: string; + @State() secondSelectValue: string; + @State() avOptions: any[] = [ + { 'id': 101, 'name': 'Mark' }, + { 'id': 102, 'name': 'Smith' } + ]; + + handleSubmit(e) { + e.preventDefault(); + console.log(this.value); + } + + handleChange(event) { + this.value = event.target.value; + + if (event.target.validity.typeMismatch) { + console.log('this element is not valid') + } + } + + handleSelect(event) { + console.log(event.target.value); + this.selectValue = event.target.value; + } + + handleSecondSelect(event) { + console.log(event.target.value); + this.secondSelectValue = event.target.value; + } + + render() { + return ( + this.handleSubmit(e)}> + + + + + + + +
    + ); + } +} +``` + +This form is a little more advanced in that it has two select inputs along with an email input. We also do validity checking of our email input in the `handleChange` method. We handle the `select` element in a very similar manner to how we handle text inputs. + +For the validity checking, we are #usingtheplatform and are using the [constraint validation api](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation) that is built right into the browser to check if the user is actually entering an email or not. diff --git a/versioned_docs/version-v4.19/guides/hydrate-app.md b/versioned_docs/version-v4.19/guides/hydrate-app.md new file mode 100644 index 000000000..37fd5c7af --- /dev/null +++ b/versioned_docs/version-v4.19/guides/hydrate-app.md @@ -0,0 +1,248 @@ +--- +title: Hydrate App +sidebar_label: Hydrate App +description: Hydrate App +slug: /hydrate-app +--- + +# Hydrate App + +The hydrate app is a Stencil output target which generates a module that can be +used on a NodeJS server to hydrate HTML and implement server side rendering (SSR). +This functionality is used internally by the Stencil compiler for +prerendering, as well as for the Angular Universal SSR for the Ionic +framework. However, like Stencil components, the hydrate app itself is not +restricted to one framework. + +_Note that Stencil does **NOT** use Puppeteer for SSR or prerendering._ + +## How to Use the Hydrate App + +Server side rendering (SSR) can be accomplished in a similar way to +prerendering. Instead of using the `--prerender` CLI flag, you can an output +target of type `'dist-hydrate-script'` to your `stencil.config.ts`, like so: + +```ts +outputTargets: [ + { + type: 'dist-hydrate-script', + }, +]; +``` + +This will generate a `hydrate` app in your root project directory that can be +imported and used by your Node server. + +After publishing your component library, you can import the hydrate app into +your server's code like this: + +```javascript +import { hydrateDocument, renderToString, streamToString } from 'yourpackage/hydrate'; +``` + +The hydrate app module exports 3 functions, `hydrateDocument`, `renderToString` and `streamToString`. `hydrateDocument` takes a [document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) as its input while `renderToString` as well as `streamToString` takes a raw HTML string. While `hydrateDocument` and `renderToString` return a Promise which wraps a result object, `streamToString` returns a [`Readable`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) stream that can be passed into a server response. + +### hydrateDocument + +You can use `hydrateDocument` as a part of your server's response logic before +serving the web page. `hydrateDocument` takes two arguments, a +[document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) and a +config object. The function returns a promise with the hydrated results, with +the hydrated HTML under the `html` property. + +*Example taken from Ionic Angular server* + + ```javascript +import { hydrateDocument } from 'yourpackage/hydrate'; + +export function hydrateComponents(doc) { + return hydrateDocument(doc) + .then((hydrateResults) => { + // execute logic based on results + console.log(hydrateResults.html); + return hydrateResults; + }); +} +``` + +#### hydrateDocument Options + + - `canonicalUrl` - string + - `constrainTimeouts` - boolean + - `clientHydrateAnnotations` - boolean + - `cookie` - string + - `direction` - string + - `language` - string + - `maxHydrateCount` - number + - `referrer` - string + - `removeScripts` - boolean + - `removeUnusedStyles` - boolean + - `resourcesUrl` - string + - `timeout` - number + - `title` - string + - `url` - string + - `userAgent` - string + +### renderToString + +The hydrate app also has a `renderToString` function that takes an HTML string +and returns a promise of `HydrateResults`. The optional second parameter is a +config object that can alter the output of the markup. Like `hydrateDocument`, +the hydrated HTML can be found under the `html` property. + +*Example taken from Ionic Core* + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ +``` + +#### renderToString Options + +##### `approximateLineWidth` + +__Type:__ `number` + +Determines when line breaks are being set when serializing the component. + +##### `prettyHtml` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` it prettifies the serialized HTML code, intends elements and escapes text nodes. + +##### `removeAttributeQuotes` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes attribute quotes when possible, e.g. replaces `someAttribute="foo"` to `someAttribute=foo`. + +##### `removeEmptyAttributes` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true` it removes attribute that don't have values, e.g. remove `class=""`. + +##### `removeHtmlComments` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes any abundant HTML comments. Stencil still requires to insert hydration comments to be able to reconcile the component. + +##### `beforeHydrate` + +__Type:__ `(document: Document, url: URL) => | Promise` + +Allows to modify the document and all its containing components to be modified before the hydration process starts. + +##### `afterHydrate` + +__Type:__ `(document: Document, url: URL, results: PrerenderUrlResults) => | Promise` + +Allows to modify the document and all its containing components after the component was rendered in the virtual DOM and before the serialization process starts. + +##### `serializeShadowRoot` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` Stencil will render a component defined with a `shadow: true` flag into a [Declarative Shadow DOM](https://developer.chrome.com/docs/css-ui/declarative-shadow-dom), e.g.: + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ +``` + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: false, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + *
    + * + * Hello, World! I'm Stencil 'Don't call me a framework' JS + *
    + *
    + * ``` + */ +``` + +If set to `false` it renders the component as scoped component. + +##### `fullDocument` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true`, Stencil will serialize a complete HTML document for a server to respond. If set to `false` it will only render the components within the given template. diff --git a/versioned_docs/version-v4.19/guides/module-bundling.md b/versioned_docs/version-v4.19/guides/module-bundling.md new file mode 100644 index 000000000..769bea76b --- /dev/null +++ b/versioned_docs/version-v4.19/guides/module-bundling.md @@ -0,0 +1,150 @@ +--- +title: Module Bundling +sidebar_label: Bundling +description: Module Bundling +slug: /module-bundling +--- + +# Module Bundling + +Stencil uses [Rollup](https://rollupjs.org/guide/en/) under the hood to bundle your components. This guide will explain and recommend certain workarounds for some of the most common bundling issues you might encounter. + +## One Component Per Module + +For Stencil to bundle your components most efficiently, you must declare a single component (class decorated with `@Component`) per *TypeScript* file, and the component itself **must** have a unique `export`. By doing so, Stencil is able to easily analyze the entire component graph within the app, and best understand how components should be bundled together. Under-the-hood it uses the Rollup bundler to efficiently bundled shared code together. Additionally, lazy-loading is a default feature of Stencil, so code-splitting is already happening automatically, and only dynamically importing components which are being used on the page. + +Modules that contain a component are entry-points, which means that no other module should import anything from them. + +The following example is **NOT** valid: + +```tsx title="src/components/my-cmp.tsx" +// This module has a component, you cannot export anything else +export function someUtilFunction() { + console.log('do stuff'); +} + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +In this case, the compiler will emit an error that looks like this: + +```bash +[ ERROR ] src/components/my-cmp.tsx:4:1 + To allow efficient bundling, modules using @Component() can only have a single export which is the component + class itself. Any other exports should be moved to a separate file. For further information check out: + https://stenciljs.com/docs/module-bundling + + L4: export function someUtilFunction() { + L5: console.log('do stuff'); +``` + +The solution is to move any shared functions or classes to a different `.ts` file, like this: + +```tsx title="src/utils.ts" +export function someUtilFunction() { + console.log('do stuff'); +} +``` + +```tsx title="src/components/my-cmp.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +```tsx title="src/components/my-cmp-two.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp-two' +}) +export class MyCmpTwo {} +``` + + +## CommonJS Dependencies + +Rollup depends on [ES modules (ESM)](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) to properly tree-shake the module graph, unfortunately, some third-party libraries ship their code using the [CommonJS](https://requirejs.org/docs/commonjs.html) module system, which is not ideal. + +Since CommonJS libraries are still common today, Stencil comes with [`rollup-plugin-commonjs`](https://github.com/rollup/rollup-plugin-commonjs) already installed and configured. + +At compiler-time, the `rollup-plugin-commonjs` plugin does a best-effort to **transform CommonJS into ESM**, but this is not always an easy task. CommonJS is dynamic by nature, while ESM is static by design. + +For further information, check out the [rollup-plugin-commonjs docs](https://github.com/rollup/plugins/tree/master/packages/commonjs). + + + +## Custom Rollup plugins + +Stencil provides an API to pass custom rollup plugins to the bundling process in `stencil.config.ts`. Under the hood, stencil ships with some built-in plugins including `node-resolve` and `commonjs`, since the execution order of some rollup plugins is important, stencil provides an API to inject custom plugin **before node-resolve** and after **commonjs transform**: + +```tsx +export const config = { + rollupPlugins: { + before: [ + // Plugins injected before rollupNodeResolve() + resolvePlugin() + ], + after: [ + // Plugins injected after commonjs() + nodePolyfills() + ] + } +} +``` + +As a rule of thumb, plugins that need to resolve modules, should be place in `before`, while code transform plugins like: `node-polyfills`, `replace`... should be placed in `after`. Follow the plugin's documentation to make sure it's executed in the right order. + + +## Node Polyfills + +Depending on which libraries a project is dependent on, the [rollup-plugin-node-polyfills](https://www.npmjs.com/package/rollup-plugin-node-polyfills) plugin may be required. In such cases, an error message similar to the following will be displayed at build time. + +```bash +[ ERROR ] Bundling Node Builtin + For the import "crypto" to be bundled from 'problematic-dep', + ensure the "rollup-plugin-node-polyfills" plugin is installed + and added to the stencil config plugins. +``` + +This is caused by some third-party dependencies that use [Node APIs](https://nodejs.org/dist/latest-v10.x/docs/api/) that are not available in the browser, the `rollup-plugin-node-polyfills` plugin works by transparently polyfilling this missing APIs in the browser. + +### 1. Install `rollup-plugin-node-polyfills`: + +```bash npm2yarn +npm install rollup-plugin-node-polyfills --save-dev +``` + +### 2. Update the `stencil.config.ts` file including the plugin: + +```tsx +import { Config } from '@stencil/core'; +import nodePolyfills from 'rollup-plugin-node-polyfills'; + +export const config: Config = { + namespace: 'mycomponents', + rollupPlugins: { + after: [ + nodePolyfills(), + ] + } +}; +``` + +:::note +`rollup-plugin-node-polyfills` is a code-transform plugin, so it needs to run AFTER the commonjs transform plugin, that's the reason it's placed in the "after" array of plugins. +::: + +## Strict Mode + +ES modules are always parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's nothing we can do about that. + +Luckily, there is absolutely no good reason not to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them. + +*Source: [https://github.com/rollup/rollup-plugin-commonjs#strict-mode](https://github.com/rollup/rollup-plugin-commonjs#strict-mode)* diff --git a/versioned_docs/version-v4.19/guides/publishing.md b/versioned_docs/version-v4.19/guides/publishing.md new file mode 100644 index 000000000..1c4acdf01 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/publishing.md @@ -0,0 +1,159 @@ +--- +title: Publishing A Component Library +sidebar_label: Publishing +description: Publishing A Component Library +slug: /publishing +--- + +There are numerous strategies to publish and distribute your component library to be consumed by external projects. One of the benefits of Stencil is that is makes it easy to generate the various [output targets](../output-targets/01-overview.md) that are right for your use-case. + +## Use Cases + +To use your Stencil components in other projects, there are two different output targets to consider: [`dist`](../output-targets/dist.md) and [`dist-custom-elements`](../output-targets/custom-elements.md). Both export your components for different use cases. Luckily, both can be generated at the same time, using the same source code, and shipped in the same distribution. It would be up to the consumer of your component library to decide which build to use. + +### Lazy Loading + +If you prefer to have your components automatically loaded when used in your application, we recommend enabling the [`dist`](../output-targets/dist.md) output target. The bundle gives you a small entry file that registers all your components and defers loading the full component logic until it is rendered in your application. It doesn't matter if the actual application is written in HTML or created with vanilla JavaScript, jQuery, React, etc. + +Your users can import your component library, e.g. called `my-design-system`, either via a `script` tag: + +```html + +``` + +or by importing it in the bootstrap script of your application: + +```ts +import 'my-design-system'; +``` + +To ensure that the right entry file is loaded when importing the project, define the following fields in your `package.json`: + +```json +{ + "exports": "./dist/esm/my-design-system.js", + "main": "./dist/cjs/my-design-system.js", + "unpkg": "dist/my-design-system/my-design-system.esm.js", +} +``` + +Read more about various options when it comes to configuring your project's components for lazy loading in the [`dist`](../output-targets/dist.md) output target section. + +#### Considerations + +To start, Stencil was designed to lazy-load itself only when the component was actually used on a page. There are many benefits to this approach, such as simply adding a script tag to any page and the entire library is available for use, yet only the components actually used are downloaded. For example, [`@ionic/core`](https://www.npmjs.com/package/@ionic/core) comes with over 100 components, but a webpage may only need `ion-toggle`. Instead of requesting the entire component library, or generating a custom bundle for just `ion-toggle`, the `dist` output target is able to generate a tiny entry build ready to load any of its components on-demand. + +However be aware that this approach is not ideal in all cases. It requires your application to ship the bundled components as static assets in order for them to load properly. Furthermore, having many nested component dependencies can have an impact on the performance of your application. For example, given you have a component `CmpA` which uses a Stencil component `CmpB` which itself uses another Stencil component `CmpC`. In order to fully render `CmpA` the browser has to load 3 scripts sequentially which can result in undesired rendering delays. + +### Standalone + +The [`dist-custom-elements`](../output-targets/custom-elements.md) output target builds each component as a stand-alone class that extends `HTMLElement`. The output is a standardized custom element with the styles already attached and without any of Stencil's lazy-loading. This may be preferred for projects that are already handling bundling, lazy-loading and defining the custom elements themselves. + +The generated files will each export a component class and will already have the styles bundled. However, this build does not define the custom elements or apply any polyfills. Static assets referenced within components will need to be set using `setAssetPath` (see [Making Assets Available](../output-targets/custom-elements.md#making-assets-available)). + +You can use these standalone components by importing them via: + +```ts +import { MyComponent, defineCustomElementMyComponent } from 'my-design-system' + +// register to CustomElementRegistry +defineCustomElementMyComponent() + +// or extend custom element via +class MyCustomComponent extends MyComponent { + // ... +} +define('my-custom-component', MyCustomComponent) +``` + +To ensure that the right entry file is loaded when importing the project, define different [exports fields](https://nodejs.org/api/packages.html#exports) in your `package.json`: + +```json +{ + "exports": { + ".": { + "import": "./dist/components/index.js", + "types": "./dist/components/index.d.ts" + }, + "./my-component": { + "import": "./dist/components/my-component.js", + "types": "./dist/components/my-component.d.ts" + } + }, + "types": "dist/components/index.d.ts", +} +``` + +This allows us to map certain import paths to specific components within our project and allows users to only import the component code they are interested in and reduce the amount of code that needs to downloaded by the browser, e.g.: + +```js +// this import loads all compiled components +import { MyComponent } from 'my-design-system' +// only import compiled code for MyComponent +import { MyComponent } from 'my-design-system/my-component' +``` + +If you define exports targets for all your components as shown above and by using [`customElementsExportBehavior: 'auto-define-custom-elements'`](../output-targets/custom-elements.md#customelementsexportbehavior) as output target option, you can skip the `defineCustomElement` call and directly import the component where you need it: + +```ts +import 'my-design-system/my-component' +``` + +:::note +If you are distributing both the `dist` and `dist-custom-elements`, then it's best to pick one of them as the main entry depending on which use case is more prominent. +::: + +Read more about various options when it comes to distributing your components as standalone components in the [`dist-custom-elements`](../output-targets/custom-elements.md) output target section. + +The output directory will also contain an `index.js` file which exports some helper methods by default. The contents of the file will look something like: + +```js +export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client'; +``` + +:::note +The contents may look different if [`customElementsExportBehavior`](../output-targets/custom-elements.md#customelementsexportbehavior) is specified! +::: + +#### Considerations + +The `dist-custom-elements` is a direct build of the custom element that extends `HTMLElement`, without any lazy-loading. This distribution strategy may be preferred for projects that use an external bundler such as [Vite](https://vitejs.dev/), [WebPack](https://webpack.js.org/) or [Rollup](https://rollupjs.org) to compile the application. They ensure that only the components used within your application are bundled into compilation. + +#### Usage in TypeScript + +If you plan to support consuming your component library in TypeScript you'll need to set `generateTypeDeclarations: true` on the output target in your `stencil.config.ts`, like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + generateTypeDeclarations: true, + }, + // ... + ], + // ... +}; +``` + +Then you can set the `types` property in `package.json` so that consumers of your package can find the type definitions, like so: + +```json title="package.json" +{ + "types": "dist/components/index.d.ts", + "dependencies": { + "@stencil/core": "latest" + }, + ... +} +``` + +:::note +If you set the `dir` property on the output target config, replace `dist/components` in the above snippet with the path set in the config. +::: + +## Publishing to NPM + +[NPM](https://www.npmjs.com/) is an online software registry for sharing libraries, tools, utilities, packages, etc. To make your Stencil project widely available to be consumed, it's recommended to [publish the component library to NPM](https://docs.npmjs.com/getting-started/publishing-npm-packages). Once the library is published to NPM, other projects are able to add your component library as a dependency and use the components within their own projects. diff --git a/versioned_docs/version-v4.19/guides/service-workers.md b/versioned_docs/version-v4.19/guides/service-workers.md new file mode 100644 index 000000000..51f37237a --- /dev/null +++ b/versioned_docs/version-v4.19/guides/service-workers.md @@ -0,0 +1,293 @@ +--- +title: Service Workers +sidebar_label: Service Workers +description: Service Workers +slug: /service-workers +--- + +# Service Workers + +[Service workers](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers) are a very powerful api that is essential for [PWAs](https://blog.ionic.io/what-is-a-progressive-web-app/), but can be hard to use. To help with this, we decided to build support for Service Workers into Stencil itself using [Workbox](https://workboxjs.org/). + +## What is Workbox? + +Workbox is a library that greatly simplifies the Service Worker API. It allows you to quickly generate a service worker that can handle caching static assets, cache remote assets using routes (similar to Express) or even do offline Google Analytics. Because we are built on top of Workbox, you can easily use any of the functionality they offer. For more info on Workbox, [check out their docs](https://developers.google.com/web/tools/workbox/) + +## Usage + +When doing a production build of an app built using Stencil, the Stencil compiler will automatically generate a service worker for you and inject the necessary code to register the service worker in your index.html. Also, because the files Stencil generates are hashed, every time you do a production build and push an update to your app, the service worker will know to update, therefore ensuring your users are never stuck on a stale version of your site. + +Lets run through the steps needed to enable service workers for your project: + +- `cd` into your project +- Run `npm run build` + +And that's it! You should now have an `sw.js` file in your `www` folder and the code to register the service worker in your `www/index.html` file. + +:::note +The component starter by default does not have service workers enabled as a service worker is not needed for component collections +::: + +## Config + +Stencil uses Workbox underneath, and by default generates a service worker from a config object using the `generateSW` mode. Therefore it supports all of the [Workbox generateSW config options](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). Here is the default config Stencil uses: + +```tsx +{ + globPatterns: [ + '**/*.{js,css,json,html}' + ] +}; +``` + +This configuration does pre-caching of all of your app's assets. + +To modify this config you can use the `serviceWorker` param of your Stencil config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + globPatterns: [ + '**/*.{js,css,json,html,ico,png}' + ] + } + } + ] +}; +``` + +### Disabling the service worker + +If you do not want a service worker to be generated during the build, this can be turned off. To disable this feature, set the `serviceWorker` property to `null` in the `www` output target. + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: null + } + ] +}; +``` + +## Using a custom service worker + +Already have a service worker or want to include some custom code? We support that, too. By specifying a source file for your service worker, Stencil switches to the `injectManifest` mode of Workbox. That gives you full control over your service worker, while still allowing you to automatically inject a precache manifest. + +Let's go through the steps needed for this functionality: + +- First we need to pass the path to our custom service worker to the `swSrc` command in the `serviceWorker` config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + swSrc: 'src/sw.js' + } + } + ] +}; +``` + +- Now we need to include some boilerplate code in our custom service worker: + +```tsx +// change to the version you get from `npm ls workbox-build` +importScripts('workbox-v4.3.1/workbox-sw.js'); + +// your custom service worker code + +// the precache manifest will be injected into the following line +self.workbox.precaching.precacheAndRoute([]); +``` + +This code imports the Workbox library, creates a new instance of the service worker and tells Workbox where to insert the pre-cache array. + +### Showing a reload toast when an update is available + +When a new service worker is available, by default, it will be downloaded and then go into a state of waiting to be activated. The new service worker won't take over until all tabs of the site are closed and the site is visited again. This is to avoid unexpected behavior from conflicts with files being served from cache, and works well in many cases. + +If you want to give your users the option to immediately access the new update, a common way is to show them a toast that lets them know about the update and offers a "reload" button. The reload let's the new service worker take over, serving the fresh content, and triggers a page reload, to avoid cache issues. + +The following example showcases this in combination with the Ionic framework, but the toast-related code should be easily adaptable to any UI. Add the following to your root component (commonly `app-root.tsx`). + +```tsx +@Listen("swUpdate", { target: 'window' }) +async onServiceWorkerUpdate() { + const registration = await navigator.serviceWorker.getRegistration(); + + if (!registration?.waiting) { + // If there is no waiting registration, this is the first service + // worker being installed. + return; + } + + const toast = await toastController.create({ + message: "New version available.", + buttons: [{ text: 'Reload', role: 'reload' }], + duration: 0 + }); + + await toast.present(); + + const { role } = await toast.onWillDismiss(); + + if (role === 'reload') { + registration.waiting.postMessage("skipWaiting"); + } +} +``` + +The `swUpdate` event is emitted by Stencil every time a new service worker is installed. When a service worker is waiting for registration, the toast is shown. After clicking the reload button, a message is posted to the waiting service worker, letting it know to take over. This message needs to be handled by the service worker; therefore we need to create a custom one (e. g. `src/sw.js`) and add a listener to call `skipWaiting()`. + +```tsx +importScripts("workbox-v4.3.1/workbox-sw.js"); + +self.addEventListener("message", ({ data }) => { + if (data === "skipWaiting") { + self.skipWaiting(); + } +}); + +self.workbox.precaching.precacheAndRoute([]); +``` + +:::note +Don't forget to set `swSrc` in your Stencil config. +::: + +Finally, we want our app to reload when the new service worker has taken over, so that no outdated code is served from the cache anymore. We can use the service worker's `controllerchange` event for that, by attaching an event listener in our root component's `componentWillLoad` lifecycle hook. + +```tsx +componentWillLoad() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker + .getRegistration() + .then(registration => { + if (registration?.active) { + navigator.serviceWorker.addEventListener( + 'controllerchange', + () => window.location.reload() + ); + } + }) + } +} +``` + +### Handle push events + +A common use case for custom service workers is to handle browser push notifications. But before we will be able show push notifications, we first need to use the Notifications API to request permissions from the user to do so. + +```tsx +if ('Notification' in window && 'serviceWorker' in navigator) { + Notification.requestPermission(status => { + // status will either be 'default', 'granted' or 'denied' + console.log(`Notification permissions have been ${status}`); + }); +} +``` + +The current permission status can always be checked using `Notification.permission`. + +To show a notification to the user after being granted permission, we can use the `showNotification` method of our service worker's registration (within our custom service worker). + +```tsx +self.registration.showNotification('Hakuna matata.'); +``` + +Usually we will have a backend that will send out push notifications to clients, and we want our service worker to handle them. To do that, we can register an event listener in our worker for the `push` event. The event will be of type [`PushEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent) and have a `data` field of type [`PushMessageData`](https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData). + +```tsx +self.addEventListener('push', event => { + console.log(`Push received with data "${event.data.text()}"`); + + const title = 'Push Notification'; + const options = { + body: `${event.data.text()}`, + data: { href: '/users/donald' }, + actions: [ + { action: 'details', title: 'Details' }, + { action: 'dismiss', title: 'Dismiss' }, + ], + }; + + event.waitUntil(self.registration.showNotification(title, options)); +}); +``` + +If the data is a JSON string, then `data.json()` can be used to immediately get the parsed data. The `event.waitUntil` method is used to ensure that the service worker doesn't terminate before the asynchronous `showNotification` operation has completed. + +Furthermore, we will likely want to handle notification clicks. The API provides the events `notificationclick` and `notificationclose` for that. + +```tsx +self.addEventListener('notificationclick', event => { + const notification = event.notification; + const action = event.action; + + if (action === 'dismiss') { + notification.close(); + } else { + // This handles both notification click and 'details' action, + // because some platforms might not support actions. + clients.openWindow(notification.data.href); + notification.close(); + } +}); +``` + +Now our service worker is able to receive and process push notifications, however we still need to register the client with our backend. Browsers provide a push service for that reason, which your app can subscribe to. The subscription object contains an endpoint URL with a unique identifier for each client. You can send your notifications to that URL, encrypted with a public key which is also provided by the subscription object. + +In order to implement this, we first need to get each client to subscribe to the browser's push service, and then send the subscription object to our backend. Then our backend can generate the push notifications, encrypt them with the public key, and send them to the subscription endpoint URL. + +First we will implement a function to subscribe the user to the push service, which as a best practice should be triggered from a user action signalling that they would like to receive push notifications. Assuming that notification permissions have already been granted, the following function can be used for that. + +```tsx +async function subscribeUser() { + if ('serviceWorker' in navigator) { + const registration = await navigator.serviceWorker.ready; + + const subscription = await registration.pushManager + .subscribe({ userVisibleOnly: true }) + .catch(console.error); + + if (!subscription) { + return; + } + + // the subscription object is what we want to send to our backend + console.log(subscription.endpoint); + } +} +``` + +We should also check our subscription every time our app is accessed, because the subscription object can change. + +```tsx +self.registration.pushManager.getSubscription().then(subscription => { + if (!subscription) { + // ask the user to register for push + return; + } + + // update the database + console.log(subscription); +}); +``` + +### Further Reading + +* For more information on push notifications and the related APIs please refer to the [Web Fundamentals Introduction to Push Notifications](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications) and the [MDN Push API docs](https://developer.mozilla.org/en-US/docs/Web/API/Push_API). +* [This Twitter thread by David Brunelle](https://twitter.com/davidbrunelle/status/1073394572980453376) explains how to implement versioning in your PWA in order to handle breaking API changes. The problem here is that your service worker enabled app will continue to serve an outdated (cached) app against your updated API. In order to solve this a version check can be implemented. diff --git a/versioned_docs/version-v4.19/guides/store.md b/versioned_docs/version-v4.19/guides/store.md new file mode 100644 index 000000000..b293435ab --- /dev/null +++ b/versioned_docs/version-v4.19/guides/store.md @@ -0,0 +1,131 @@ +--- +title: 'Store' +sidebar_label: Stencil Store +description: Store +slug: /stencil-store +--- + +# @stencil/store + +[Store](https://github.com/ionic-team/stencil-store) is a lightweight shared state library by the stencil core team. It implements a simple key/value map that efficiently re-renders components when necessary. + +- Lightweight +- Zero dependencies +- Simple API, like a reactive Map +- Best performance + +## Installation + +```bash npm2yarn +npm install @stencil/store --save-dev +``` + +## Example + +**store.ts:** + +```tsx +import { createStore } from "@stencil/store"; + +const { state, onChange } = createStore({ + clicks: 0, + seconds: 0, + squaredClicks: 0 +}); + +onChange('clicks', value => { + state.squaredClicks = value ** 2; +}); + +export default state; +``` + +**component.tsx:** + +```tsx +import { Component, h } from '@stencil/core'; +import state from '../store'; + +@Component({ + tag: 'app-profile', +}) +export class AppProfile { + + componentWillLoad() { + setInterval(() => state.seconds++, 1000); + } + + render() { + return ( +
    +

    + +

    + Seconds: {state.seconds} +
    + Squared Clicks: {state.squaredClicks} +

    +

    +
    + ); + } +} + +const MyGlobalCounter = () => { + return ( + + ); +}; +``` + +## API + +### `createStore(initialState)` + +Create a new store with the given initial state. The type is inferred from `initialState`, or can be passed as the generic type `T`. + +Returns a `store` object with the following properties. + +### `store.state` + +The state object is proxied, I.E. you can directly get and set properties and Store will automatically take care of component re-rendering when the state object is changed. + +### `store.on(event, listener)` + +Add a listener to the store for a certain action. + +### `store.onChange(propName, listener)` + +Add a listener that is called when a specific property changes. + +### `store.get(propName)` + +Get a property's value from the store. + +### `store.set(propName, value)` + +Set a property's value in the store. + +### `store.reset()` + +Reset the store to its initial state. + +### `store.use(...subscriptions)` + +Use the given subscriptions in the store. A subscription is an object that defines one or more of the properties `get`, `set` or `reset`. + + +## Testing + +Like any global state library, state should be reset between each spec test. +Use the `dispose()` API in the `beforeEach` hook. + +```ts +import store from '../store'; + +beforeEach(() => { + store.dispose(); +}); +``` diff --git a/versioned_docs/version-v4.19/guides/style-guide.md b/versioned_docs/version-v4.19/guides/style-guide.md new file mode 100644 index 000000000..1f18b31d1 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/style-guide.md @@ -0,0 +1,269 @@ +--- +title: Stencil Style Guide +sidebar_label: Style Guide +description: Stencil Style Guide +slug: /style-guide +--- + +# Stencil Style Guide + +This is a component style guide created and enforced internally by the core team of Stencil, for the purpose of standardizing Stencil components. This should only be used as a reference for other teams in creating their own style guides. Feel free to modify to your team's own preference. + +:::note +In order to enforce this (or your team's) style guide, we recommend leveraging a static analysis tool like [ESLint](https://eslint.org/). [@stencil-community/eslint-plugin](https://www.npmjs.com/package/@stencil-community/eslint-plugin) provides rules specifically for writing Stencil components. +::: + +:::note +This guide once recommended TSLint as a static analysis tool. TSLint has been deprecated by its maintaining organization in favor of ESLint and is no longer recommended by the Stencil team. +::: + +## File structure + +- One component per file. +- One component per directory. Though it may make sense to group similar components into the same directory, we've found it's easier to document components when each one has its own directory. +- Implementation (.tsx) and styles of a component should live in the same directory. + +Example from ionic-core: + +```bash +├── my-card +│ ├── my-card.ios.css +│ ├── my-card.md.css +│ ├── my-card.css +│ ├── my-card.tsx +│ └── test +│ └── basic +│ ├── e2e.js +│ └── index.html +├── my-card-content +│ ├── my-card-content.ios.css +│ ├── my-card-content.md.css +│ ├── my-card-content.css +│ └── my-card-content.tsx +├── my-card-title +│ ├── my-card-title.ios.css +│ ├── my-card-title.md.css +│ ├── my-card-title.css +``` + + +## Naming +### HTML tag + +#### Prefix +The prefix has a major role when you are creating a collection of components intended to be used across different projects, like [@ionic/core](https://www.npmjs.com/package/@ionic/core). Web Components are not scoped because they are globally declared within the webpage, which means a "unique" prefix is needed to prevent collisions. The prefix also helps to quickly identify the collection a component is part of. Additionally, web components are required to contain a "-" dash within the tag name, so using the first section to namespace your components is a natural fit. + +We do not recommend using "stencil" as prefix, since Stencil DOES NOT emit stencil components, but rather the output is standards compliant web components. + +DO NOT do this: +```markup + + +``` + +Instead, use your own naming or brand. For example, [Ionic](https://ionicframework.com/) components are all prefixed with `ion-`. +```markup + + +``` + +#### Name + +Components are not actions, they are conceptually "things". It is better to use nouns instead of verbs, such as "animation" instead of "animating". "input", "tab", "nav", "menu" are some examples. + + +#### Modifiers + +When several components are related and/or coupled, it is a good idea to share the name, and then add different modifiers, for example: + +```markup + + + +``` + + +### Component (TS class) + +The name of the ES6 class of the component SHOULD NOT have a prefix since classes are scoped. There is no risk of collision. + +```tsx +@Component({ + tag: 'ion-button' +}) +export class Button { ... } + +@Component({ + tag: 'ion-menu' +}) +export class Menu { ... } +``` + + +## TypeScript + +1. **Use private variables and methods as much possible:** They are useful to detect dead code and enforce encapsulation. Note that this is a feature which TypeScript provides to help harden your code, but using `private`, `public` or `protected` does not make a difference in the actual JavaScript output. + +2. **Code with Method/Prop/Event/Component decorators should have JSDocs:** This allows for documentation generation and for better user experience in an editor that has TypeScript intellisense + +## Code organization + +**Newspaper Metaphor from The Robert C. Martin's _Clean Code_** + +:::note +The source file should be organized like a newspaper article, with the highest level summary at the top, and more and more details further down. Functions called from the top function come directly below it, and so on down to the lowest level and most detailed functions at the bottom. This is a good way to organize the source code, even though IDEs make the location of functions less important, since it is so easy to navigate in and out of them. +::: + +### High level example (commented) + +```tsx +@Component({ + tag: 'ion-something', + styleUrls: { + ios: 'something.ios.css', + md: 'something.md.css', + wp: 'something.wp.css' + } +}) +export class Something { + + /** + * 1. Own Properties + * Always set the type if a default value has not + * been set. If a default value is being set, then type + * is already inferred. List the own properties in + * alphabetical order. Note that because these properties + * do not have the @Prop() decorator, they will not be exposed + * publicly on the host element, but only used internally. + */ + num: number; + someText = 'default'; + + /** + * 2. Reference to host HTML element. + * Inlined decorator + */ + @Element() el: HTMLElement; + + /** + * 3. State() variables + * Inlined decorator, alphabetical order. + */ + @State() isValidated: boolean; + @State() status = 0; + + /** + * 4. Public Property API + * Inlined decorator, alphabetical order. These are + * different than "own properties" in that public props + * are exposed as properties and attributes on the host element. + * Requires JSDocs for public API documentation. + */ + @Prop() content: string; + @Prop() enabled: boolean; + @Prop() menuId: string; + @Prop() type = 'overlay'; + + /** + * Prop lifecycle events SHOULD go just behind the Prop they listen to. + * This makes sense since both statements are strongly connected. + * - If renaming the instance variable name you must also update the name in @Watch() + * - Code is easier to follow and maintain. + */ + @Prop() swipeEnabled = true; + + @Watch('swipeEnabled') + swipeEnabledChanged(newSwipeEnabled: boolean, oldSwipeEnabled: boolean) { + this.updateState(); + } + + /** + * 5. Events section + * Inlined decorator, alphabetical order. + * Requires JSDocs for public API documentation. + */ + @Event() ionClose: EventEmitter; + @Event() ionDrag: EventEmitter; + @Event() ionOpen: EventEmitter; + + /** + * 6. Component lifecycle events + * Ordered by their natural call order, for example + * WillLoad should go before DidLoad. + */ + connectedCallback() {} + disconnectedCallback() {} + componentWillLoad() {} + componentDidLoad() {} + componentShouldUpdate(newVal: any, oldVal: any, propName: string) {} + componentWillUpdate() {} + componentDidUpdate() {} + componentWillRender() {} + componentDidRender() {} + + /** + * 7. Listeners + * It is ok to place them in a different location + * if makes more sense in the context. Recommend + * starting a listener method with "on". + * Always use two lines. + */ + @Listen('click', { enabled: false }) + onClick(ev: UIEvent) { + console.log('hi!') + } + + /** + * 8. Public methods API + * These methods are exposed on the host element. + * Always use two lines. + * Public Methods must be async. + * Requires JSDocs for public API documentation. + */ + @Method() + async open(): Promise { + // ... + return true; + } + + @Method() + async close(): Promise { + // ... + } + + /** + * 9. Local methods + * Internal business logic. These methods cannot be + * called from the host element. + */ + prepareAnimation(): Promise { + // ... + } + + updateState() { + // ... + } + + /** + * 10. render() function + * Always the last public method in the class. + * If private methods present, they are below public methods. + */ + render() { + return ( + + + + ); + } +} +``` diff --git a/versioned_docs/version-v4.19/guides/typed-components.md b/versioned_docs/version-v4.19/guides/typed-components.md new file mode 100644 index 000000000..243efed31 --- /dev/null +++ b/versioned_docs/version-v4.19/guides/typed-components.md @@ -0,0 +1,46 @@ +--- +title: Typed Components +sidebar_label: Typed Components +description: Typed Components +slug: /typed-components +--- + +# Typed Components + +Web Components generated with Stencil come with type declaration files automatically generated by the Stencil compiler. + +In general, TypeScript declarations provide strong guarantees when consuming components: + +- Ensuring that proper values are passed down as properties +- Code autocompletion in modern IDEs such as VSCode +- Events' details +- Signature of components' methods + +These public types are automatically generated by Stencil in `src/component.d.ts`. +This file allows for strong typing in JSX (just like React) and `HTMLElement` interfaces for each component. + +:::tip +It is recommended that this file be checked in with the rest of your code in source control. +::: + +Because Web Components generated by Stencil are just vanilla Web Components, they extend the `HTMLElement` interface. +For each component a type named `HTML{CamelCaseTag}Element` is registered at the global scope. +This means developers DO NOT have to import them explicitly, just like `HTMLElement` or `HTMLScriptElement` are not imported. + +- `ion-button` => `HTMLIonButtonElement` +- `ion-menu-controller` => `HTMLIonMenuControllerElement` + +```tsx +const button: HTMLIonButtonElement = document.queryElement('ion-button'); +button.fill = 'outline'; +``` + +**IMPORTANT**: always use the `HTML{}Element` interfaces in order to hold references to components. + +## Properties + +This section has moved to [Property Types](../components/properties.md#types) + +### Required Properties + +This section has moved to [Required Properties](../components/properties.md#required-properties) diff --git a/versioned_docs/version-v4.19/guides/vs-code-debugging.md b/versioned_docs/version-v4.19/guides/vs-code-debugging.md new file mode 100644 index 000000000..835a3b66a --- /dev/null +++ b/versioned_docs/version-v4.19/guides/vs-code-debugging.md @@ -0,0 +1,126 @@ +--- +title: Debugging With VS Code +sidebar_label: VS Code Debugging +description: How to debug a Stencil component using VS Code +slug: /vs-code-debugging +--- + +# Debugging With VS Code + +VS Code offers a streamlined debugging experience that can be started with a single click when using [launch configurations](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations). + +If you're unfamiliar with using the VS Code debugger in general, please visit the [VS Code debugger documentation](https://code.visualstudio.com/docs/editor/debugging) for a primer. + +## Requirements for Debugging + +In order for a debugger to function, the Stencil project must be configured to generate source maps for the compiled web components back to the source code. As of Stencil v3, source maps are generated by default, but be sure to double-check the project's Stencil config does not disable this behavior. More information regarding source maps in Stencil can be found in the [project configuration documentation](../config/01-overview.md#sourcemap). + +## Debugging Stencil Components In a Web App + +It's a common use case to want to step through a web component's code as it executes in the browser and VS Code makes that process simple. Combining the debugger with Stencil's dev server in watch mode will allow you to debug changes as they're made. + +### Configuring the VS Code Debugger + +To debug Stencil components as they run in a browser (web app), create (or edit) the `.vscode/launch.json` file with the following configuration: + +```json title=".vscode/launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3333", + "sourceMaps": true, + "sourceMapPathOverrides": { + "*": "${webRoot}/*" + } + } + ] +} +``` + +:::note +If your Stencil project is within a monorepo structure, you may want (or need) to add the `webRoot` option to the above config to point to the Stencil project's directory. For instance, if you have your Stencil project at `/packages/stencil-library`, you would add the following to the config: + +```json +{ + ..., + "webRoot": "${workspaceFolder}/packages/stencil-library", +} +``` + +::: + +This will create a configuration to open a Chrome debugger instance on port 3333 (the default port used by the Stencil dev server). To use this configuration, start a Stencil dev server (running `npm start` in a [Stencil component starter project](https://stenciljs.com/docs/getting-started)) and then run the configuration from the VS Code debugger tab. At this point, any breakpoints set in the component source code will pause browser execution when hit. + +:::note +If your Stencil project is [configured to use a different port](https://stenciljs.com/docs/dev-server#dev-server-config) for the dev server, you will need to update the `url` property in the debugger configuration with the correct port. +::: + +## Debugging Static Site Generation (SSG) + +Static Site Generation, also known as prerendering, executes your components at build time to generate a snapshot of the rendered styles and markup to be efficiently served to search engines and users on first request. + +Since this step runs in a Node.js process instead of a browser, debugging can't be done directly in the browser. However, debugging is straightforward using existing Node.js debugging techniques. + +### Overview + +The `stencil build --prerender` command will first build the hydrate script for a NodeJS environment, then prerender the site using the build. For a production build this is probably ideal. + +However, while debugging you may not need to keep rebuilding the hydrate script, but you only need to debug through the prerendering process. Stencil creates a file in `dist/hydrate` that is used to actually execute your components. + +To only prerender (and avoid rebuilding), you can use the `stencil prerender dist/hydrate/index.js` command, with the path to the script as a flag. + +### Tips for Debugging Prerendering + +By default, prerendering will start by rendering the homepage, find links within the homepage, and continue to crawl the entire site as it finds more links. While debugging, it might be easier to _not_ crawl every URL in the site, but rather have it only prerender one page. To disable crawling, set the prerender config `crawlUrls: false`. + +Next, you can use the `entryUrls` config to provide an array of paths to prerender, rather than starting at the homepage. + +Additionally, console logs that are printed within the runtime are suppressed while prerendering (otherwise the terminal would be overloaded with logs). By setting `runtimeLogging: true`, the runtime console logs will be printed in the terminal. Below is an example setup for prerender debugging: + +```tsx title="prerender.config.ts" +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + crawlUrls: false, + entryUrls: ['/example'], + hydrateOptions: (_url) => { + return { + runtimeLogging: true, + }; + }, +}; +``` + +### Configuring the VS Code Debugger + +To debug the Stencil prerender process, create (or edit) the `launch.json` file with the following configuration: + +```json title="launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "node", + "request": "launch", + "name": "Prerender", + "args": [ + "${workspaceFolder}/node_modules/@stencil/core/bin/stencil", + "prerender", + "${workspaceFolder}/dist/hydrate/index.js", + "--max-workers=0", + "--config=${workspaceFolder}/stencil.config.ts" + ], + "protocol": "inspector" + } + ] +} +``` + +This creates a new debugging configuration using the script that hydrates the app. We're starting up the `stencil prerender` command, and providing it a path to where +the hydrate script can be found. Next we're using `--max-workers=0` so we do not fork numerous processes to each of your CPUs which will make it difficult to debug. diff --git a/versioned_docs/version-v4.19/guides/workers.md b/versioned_docs/version-v4.19/guides/workers.md new file mode 100644 index 000000000..f3e5385cf --- /dev/null +++ b/versioned_docs/version-v4.19/guides/workers.md @@ -0,0 +1,284 @@ +--- +title: Web Workers +sidebar_label: Web Workers +description: Web Workers +slug: /web-workers +--- + +# Web Workers + +[Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) are a widely supported technology (Chrome, Firefox, Safari and Edge) that allows JavaScript to execute in a different thread, maximizing the usage of multiple CPUs; but most importantly not blocking the **main thread**. + +The **main thread** is where JavaScript runs by default and has access to the `document`, `window` and other DOM APIs. The problem is that long-running JS prevents the browser from running smooth animations (CSS animations, transitions, canvas, svg...), making your site look frozen. That's why if your application needs to run CPU-intensive tasks, Web Workers are a great help. + + +## When to use Web Workers? + +The first thing to understand is when to use a Web Workers, and when *not* to use them since they come with a set of costs and limitations: + +- There is no access to the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction). This means you cannot interact with `document`, `window` or any elements in the page. +- There is no access to any of the `@stencil/core` APIs. For example, you cannot declare and use a component in a Web Worker, for the same reasons there is **no access to the DOM**. +- A Web Worker has its own **isolated state** since each worker has their own memory space. For example, a variable declared on the main thread cannot be directly referenced from a worker. +- There is an overhead when passing data between workers and the main thread. As a general rule, it's best to minimize the amount of data sent to and from the worker and be mindful if the work to send your data takes more time than doing it on the main thread. +- Communication is always **asynchronous**. Luckily Promises and async/await makes this relatively easy, but it's important to understand that communication between threads is always asynchronous. +- You can **only** pass [primitives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Primitive_values) and objects that implement the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). Best way to think of it is any data that can be serialized to JSON is safe to use. + +In short, it's generally a good idea to use workers to move logic that is thread-blocking -- or UI-blocking, preventing users from interacting with the page -- into a Web Worker, such as real-time code syntax highlighting. + +## Best Practices when using Web Workers + +- Use pure and functional algorithms in workers. `(input1, input2) => output`. +- The worker logic itself can be as complex as it has to be, however, the input and output data should stay fairly simple. +- Look for ways to reduce passing data between the main thread and worker thread. +- Class instances cannot be passed as data. Instead, only work with data can be JSON serializable. +- Minimize state within the worker, or better yet, completely avoid maintaining any state (e.g., don't put redux inside a worker). +- The cost of a worker should be easily amortized because it would be doing some CPU-intensive jobs. + + +## How vanilla Web Workers "work"? + +The browser comes with a `Worker` API, that works the following way: + +```tsx +const worker = new Worker('/my-worker.js'); +worker.postMessage(['send message to worker']); +worker.onmessage = (ev) => { + console.log('data from worker', ev.data); +}; +``` + +This API, while powerful, is very low level and makes it tedious to write complex apps, since the event-driven paradigm leads easily to [spaghetti-code](https://en.wikipedia.org/wiki/Spaghetti_code), and quickly misses out on strongly-typed functions and data. + +For further information, check out [this fantastic tutorial](https://www.html5rocks.com/en/tutorials/workers/basics/) by our friends at HTML5Rocks. + +A Web Worker also requires the generation of a separate JavaScript bundle, such as the `my-worker.js` file in the example above. This means you usually need extra build scripts and tooling that transpiles and bundles the worker entry point into another `.js` file. Additionally, the main bundle must be able to reference the worker bundle's file location, which is oftentimes a challenge after transpiling, bundling, minifying, filename hashing and deploying to production servers. + +Fortunately, Stencil can help you solve these two problems: + +- Tooling: Transpiling, bundling, hashing, worker url path referencing +- Communication: Converting event-based communication to Promises, while still maintaining types. + +## Web Workers with Stencil + +As we already mention, Stencil's compiler can help you to use workers in production seamlessly. Any TypeScript file within the `src` directory that ends with `.worker.ts` will automatically use a worker. For example: + +**src/stuff.worker.ts:** + +```tsx + +export const sum = async (a: number, b: number) => { + return a + b; +} + +export const expensiveTask = async (buffer: ArrayBuffer) => { + for (let i = 0; i < buffer.length; i++) { + // do a lot of processing + } + return buffer; +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; + +// Import the worker directly. +// Stencil will automatically create +// a proxy and run the module in a worker. +// IDEs and TypeScript will treat this import +// no differently than any other ESM import. +import { sum, expensiveTask } from '../../stuff.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + async componentWillLoad() { + // sum() will run inside a worker! and the result is a Promise + const result = await sum(1, 2); + console.log(result); // 3 + + // expensiveTask() will not block the main thread, + // because it runs in parallel inside the worker. + // Note that the functions must be async. + const newBuffer = await expensiveTask(buffer); + console.log(newBuffer); + } +} +``` + + +Under the hood, Stencil compiles a worker file and uses the standard `new Worker()` API to instantiate the worker. Then it creates proxies for each of the exported functions, so developers can interact with it using [structured programming constructs](https://en.wikipedia.org/wiki/Structured_programming) instead of event-based ones. + +:::note +Workers are already placed in a different chunk, and dynamically loaded using `new Worker()`. You should avoid using a dynamic `import()` to load them, as this will cause two network requests. Instead, use ES module imports as it's only importing the proxies for communicating with the worker. +::: + +### Imports within a worker + +Normal `ESM` imports are possible when building workers in Stencil. Under the hood, the compiler bundles all the dependencies of a worker into a single file that becomes the worker's entry-point, a dependency-free file that can run without problems. + +**src/loader.worker.ts:** + +```tsx +import upngjs from 'upng-js'; +import { Images } from './materials'; + +export const loadTexture = async (imagesSrcs: Images) => { + const images = await Promise.all( + imagesSrcs.map(loadOriginalImage) + ); + return images; +} + +async function loadOriginalImage(src: string) { + const res = await fetch(src); + const png = upngjs.decode(await res.arrayBuffer()); + return png; +} +``` + +In this example, we are building a worker called `loader.worker.ts` that imports an NPM dependency (`upngjs`, used to parse png files), and a local module (`./materials`). Stencil will use [Rollup](https://rollupjs.org/guide/en/) to bundle all dependencies and remove all imports at runtime. Be aware that code will be duplicated if imported inside and outside a worker. + +#### Dynamic imports + +In order to load scripts dynamically inside of a worker, Web Workers come with a handy API, [`importScript()`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts). + +Here's an example of how to use `typescript` directly from a CDN with `importScript()`. + +```tsx +importScripts("https://cdn.jsdelivr.net/npm/typescript@latest/lib/typescript.js"); +``` + +:::note +Do not use `importScript()` to import NPM dependencies you have installed using `npm` or `yarn`. Use normal ES module imports as usual, so the bundler can understand it. +::: + +### Worker Callbacks + +In most cases, waiting for a Promise to resolve with the output data is all we'll need. However, a limitation with native Promises is that it provides only one returned value. Where a traditional callback still shines is that it can be called numerous times with different data. + +Let's say that we have a long running process that may take a few seconds to complete. With a Promise, we're unable to periodically receive the progress of the task, since all we can do is wait for Promise to resolve. + +A feature with Stencil's worker is the ability to pass a callback to the method, and within the worker, execute the callback as much as it's needed before the task resolves. + +In the example below, the task is given a number that it counts down from the number provided, and the task completes when it gets to `0`. During the count down, however, the main thread will still receive an update every second. This example will console log from `5` to `0` + + +**src/countdown.worker.ts:** + +```tsx +export const countDown = (num: number, progress: (p: number) => void) => { + return new Promise(resolve => { + const tmr = setInterval(() => { + num--; + if (num > 0) { + progress(num); + } else { + clearInterval(tmr); + resolve(num); + } + }, 1000); + }); +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; +import { countDown } from '../countdown.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + const startNum = 5; + console.log('start', startNum); + + countDown(startNum, (p) => { + console.log('progress', p); + }).then(result => { + console.log('finish', result); + }); + } +} +``` + +When executed, the result would take 5 seconds and would log: + +``` +start 5 +progress 4 +progress 3 +progress 2 +progress 1 +finish 0 +``` + +## Advanced cases + +Sometimes it might be necessary to access the actual [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) instance, because manual usage of the [`postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage) and [`onmessage`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/onmessage) is desired. However, there's still a tooling challenge in having to bundle the worker, and have the main bundle correctly reference the worker bundle url path. In that case, Stencil also has an API that exposes the worker directly so it can be used instead of the proxies mentioned early. + +For a direct worker reference, add `?worker` at the end of an ESM import. This virtual ES module will export: +- `worker`: The actual Worker instance. +- `workerPath`: The path to the worker's entry-point (usually a path to a `.js` file). +- `workerName`: The name of the worker, useful for debugging purposes. + + +**src/my-app/my-app.tsx:** + +```tsx +import { Component } from '@stencil/core'; +import { sum } from '../../stuff.worker'; + +// Using the ?worker query, allows to access the worker instance directly. +import { worker } from '../../stuff.worker.ts?worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + // Use worker api directly + worker.postMessage(['send data manually']); + + // Use the proxy + const result = await sum(1, 2); + console.log(result); // 3 + } +} +``` + +You can even use this feature you create multiple Worker manually: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; + +const workerPool = [ + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), +]; +``` + +In this example, we exclusively take advantage of the bundling performed by the compiler to obtain the `workerPath` to the worker's entry point, then manually create a pool of workers. + +:::note +Stencil will not instantiate a worker if it's unused, it takes advantage of tree-shaking to do this. +::: + +#### Worker Termination + +Any Web Workers can be terminated using the [`Worker.terminate()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) API, but since Stencil creates one worker shared across all the proxied methods, it's not recommended to terminate it manually. If you have a use-case for using `terminate` and rebuilding workers, then we recommend using the `workerPath` and creating a new Worker directly: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; +const worker = new Worker(workerPath); +// ... +worker.terminate() +``` diff --git a/versioned_docs/version-v4.19/introduction/01-overview.md b/versioned_docs/version-v4.19/introduction/01-overview.md new file mode 100644 index 000000000..a05312401 --- /dev/null +++ b/versioned_docs/version-v4.19/introduction/01-overview.md @@ -0,0 +1,48 @@ +--- +title: Stencil - A Compiler for Web Components +sidebar_label: Overview +description: Stencil has a number of add-ons that you can use with the build process. +slug: /introduction +--- + +# Overview + +## Stencil: A Web Components Compiler + +Stencil is a compiler that generates Web Components (more specifically, Custom Elements). Stencil combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil uses TypeScript, JSX, and CSS to create standards-compliant Web Components that can be used to craft high quality component libraries. + +Web Components generated with Stencil can be used with popular frameworks right +out of the box. In addition, Stencil can generate framework-specific wrappers that +allow Stencil components to be used with a framework-specific developer experience. + +Compared with using the [Custom Elements +APIs](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) +directly, Stencil provides [convenient APIs](../components/api.md) which make writing fast +components simpler. With a Virtual DOM, JSX, and async rendering, it is easy to +create fast and powerful components which are still 100% compatible with Web +Components standards. In addition to making it easier to author Custom +Elements, Stencil also adds a number of key capabilities on top of Web +Components, such as prerendering and objects-as-properties (instead of just +strings). + +The developer experience is also tuned, and comes with live reload and a small dev server baked in to the compiler. + +## How can I use Stencil? + +### Design Systems & Component Libraries + +Stencil's primary objective is providing amazing tools for design systems and component libraries. Components as a concept provide similar language for engineers and designers to have productive conversations about design implementation. [Visit the Stencil for Design Systems page to learn more.](../guides/design-systems.md) + +## The History of Stencil + +Stencil was originally created by the **[Ionic Framework](http://ionicframework.com/)** team in order to build faster, more capable components that worked across every major framework. + +The emergence of Progressive Web Apps as a rapidly growing target for web developers demanded a different approach to web app development performance. With Ionic's classic use of traditional frameworks and bundling techniques, the team was struggling to meet latency and code size demands for Progressive Web Apps that ran equally well on fast and slow networks, across a diversity of platforms and devices. + +Additionally, framework fragmentation had created a web development interoperability nightmare, where components built for one framework didn't work with another framework. + +Web Components offered a solution to both problems, pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + +Web Components by themselves, however, weren't enough. Building fast web apps required innovations that were previously locked up inside of traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. While Stencil is intended to be used primarily to build design systems and component libraries, these innovations allowed entire applications to be built using only Stencil. diff --git a/versioned_docs/version-v4.19/introduction/02-goals-and-objectives.md b/versioned_docs/version-v4.19/introduction/02-goals-and-objectives.md new file mode 100644 index 000000000..7538e2a8b --- /dev/null +++ b/versioned_docs/version-v4.19/introduction/02-goals-and-objectives.md @@ -0,0 +1,31 @@ +--- +title: Stencil Goals and Objectives +sidebar_label: Goals and Objectives +description: Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. +slug: /goals-and-objectives +--- + +# Stencil Goals And Objectives + +Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. It's important to stress that Stencil's goal is to *not* become or be seen as a "framework", but rather our goal is to provide a great developer experience and tooling expected from a framework, while using web-standards within the browser at run-time. In many cases, Stencil can be used as a drop in replacement for traditional frontend frameworks given the capabilities now available in the browser, though using it as such is certainly not required. + +## Web Standards +Components generated by Stencil in the end are built on top of web components, so they work in any major framework or with no framework at all. Additionally, other standards heavily relied on include ES Modules and dynamic imports which have proven to replace traditional bundlers which add unnecessary complexities and run-time JavaScript. By using web-standards, developers can learn and adopt a standard API documented across the world, rather than custom framework APIs that continue to change. + +## Automatic Optimizations +There are countless optimizations and tweaks developers must do to improve performance of components and websites. With a compiler, Stencil is able to analyze component code as an input, and generate optimized components as an output. + +## Future-Friendly +As the world of software development continues to evolve, so too can the compiler. Instead of requiring complete rewrites of components, the compiler can continue to make optimizations using the standard component model as the common input. The compiler allows developers to create future-friendly components, while still staying up-to-date on the latest optimizations without starting over again and again. Additionally, if something changes about any API, the compiler is able to make automatic adjustments and notify the developer exactly what needs to be updated. + +## Run-time Performance +Instead of writing custom client-side JavaScript which every user needs to download and parse for the app to work, Stencil instead prefers to use the already amazing APIs built directly within the browser. These APIs include Custom Elements. + +## Tiny API +Stencil purposely does not come with a large custom API which needs to be learned and re-learned, but rather heavily relies on, you guessed it, web-standards. Again, our goal is to not create yet-another-framework, but rather provide tooling for developers to generate future-friendly components using APIs already baked within the browser. The smaller the API, the easier to learn, and the less that can be broken. + +## Framework Features During Development +If you haven't noticed already we think web-standards are great and offer many benefits. While using web-standards without any structure is certainly possible, and there are actually many use-cases where this would be appropriate, we found that as apps and teams scale it quickly becomes difficult to manage. Developers often gravitate to frameworks because of their great tooling, defined structure, and ability to allow developers to build apps quickly. One of the largest goals of Stencil is to be that intersection of having great framework features and first-class tooling during development but generating future-proof web-standard code, rather than custom framework specific code. + +## Wide Browser Support +For the small minority of browsers that do not support modern browser features and APIs, Stencil will automatically polyfill them on-demand. What this means is that for browsers that already support the feature natively, they will not have to download and parse any unnecessary JavaScript. The great news is that in today's web landscape, most modern APIs are already shipping for what Stencil requires. diff --git a/versioned_docs/version-v4.19/introduction/03-getting-started.md b/versioned_docs/version-v4.19/introduction/03-getting-started.md new file mode 100644 index 000000000..c7a2bb064 --- /dev/null +++ b/versioned_docs/version-v4.19/introduction/03-getting-started.md @@ -0,0 +1,222 @@ +--- +title: Getting Started +sidebar_label: Getting Started +description: Getting Started +slug: /getting-started +--- + +# Getting Started + +## Starting a New Project + +### Prerequisites +Stencil requires a recent LTS version of [NodeJS](https://nodejs.org/) and npm/yarn. +Make sure you've installed and/or updated Node before continuing. + +### Running the `create-stencil` CLI +The `create-stencil` CLI can be used to scaffold a new Stencil project, and can be run using the following command: + +```bash npm2yarn + npm init stencil +``` + +Stencil can be used to create standalone components, or entire apps. +`create-stencil`, will provide a prompt so that you can choose the type of project to start: + +```text +? Select a starter project. + +Starters marked as [community] are developed by the Stencil +Community, rather than Ionic. For more information on the +Stencil Community, please see github.com/stencil-community + +❯ component Collection of web components that can be + used anywhere + app [community] Minimal starter for building a Stencil + app or website + ionic-pwa [community] Ionic PWA starter with tabs layout and routes +``` + +Selecting the 'component' option will prompt you for the name of your project. +Here, we'll name our project 'my-first-stencil-project': + +```bash +✔ Pick a starter › component +? Project name › my-first-stencil-project +``` + +After hitting `ENTER` to confirm your choices, the CLI will scaffold a Stencil project for us in a directory that matches the provided project name. +Upon successfully creating our project, the CLI will print something similar to the following to the console: + +```bash +✔ Project name › my-first-stencil-project +✔ A new git repo was initialized +✔ All setup in 26 ms + + We suggest that you begin by typing: + + $ cd my-first-stencil-project + $ npm install + $ npm start + + $ npm start + Starts the development server. + + $ npm run build + Builds your project in production mode. + + $ npm test + Starts the test runner. + + Further reading: + + - https://github.com/ionic-team/stencil-component-starter + + Happy coding! 🎈 +``` + +The first section describes a few commands required to finish getting your project bootstrapped. + +```bash npm2yarn +cd my-first-stencil-project +npm install +npm start +``` + +This will change your current directory to `my-first-stencil-project`, install your dependencies for you, and start the development server. + +### Useful Initial Commands + +The second section of the `create-stencil` output describes a few useful commands available during the development process: + +- `npm start` starts a local development server. The development server will open a new browser tab containing your +project's components. The dev-server uses hot-module reloading to update your components in the browser as you modify +them for a rapid feedback cycle. + +- `npm run build` creates a production-ready version of your components. The components generated in this step are not +meant to be used in the local development server, but rather within a project that consumes your components. + +- `npm test` runs your project's tests. The `create-stencil` CLI has created both end-to-end and unit tests when scaffolding your project. + +### Source Control + +As of create-stencil v3.3.0, a new git repository will be automatically created for you when you initialize a project if: +1. git is installed +2. Your project is not created under another git work tree (e.g. if you create a new project in a monorepo, a new git repo will not be created) + +Versions of create-stencil prior to v3.3.0 do not interact with any version control systems (VCS). +If you wish to place your project under version control, we recommend initializing your VCS now. +If you wish to use git, run the following after changing your current directory to the root of your Stencil project: + +```bash +$ git init +$ git add -A +$ git commit -m "initialize project using stencil cli" +``` + +## My First Component + +Stencil components are created by adding a new file with a `.tsx` extension, such as `my-component.tsx`. +The `.tsx` extension is required since Stencil components are built using [JSX](../components/templating-and-jsx.md) and TypeScript. + +When we ran `create-stencil` above, it generated a component, `my-component.tsx`, that can be found in the `src/components/my-component` directory: + +```tsx title="my-component.tsx" +import { Component, Prop, h } from '@stencil/core'; +import { format } from '../../utils/utils'; + +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +export class MyComponent { + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; + + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +} +``` + +Once compiled, this component can be used in HTML just like any other tag. + +```markup + +``` + +When rendered, the browser will display `Hello World! I'm Stencil 'Don't call me a framework' JS`. + +### Anatomy of `my-component` + +Let's dive in and describe what's happening in `my-component`, line-by-line. + +After the import statements, the first piece we see is the [`@Component` decorator](../components/component.md): +```tsx +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +``` +This decorator provides metadata about our component to the Stencil compiler. +Information, such as the custom element name (`tag`) to use, can be set here. +This decorator tells Stencil to: +- Set the [element's name](../components/component.md#tag) to 'my-component' +- [Apply the stylesheet](../components/component.md#styleurl) 'my-component.css' to the component +- Enable [native Shadow DOM functionality](../components/component.md#shadow) for this component + +Below the `@Component()` decorator, we have a standard JavaScript class declaration: + +```tsx +export class MyComponent { +``` + +Within this class is where you'll write the bulk of your code to bring your Stencil component to life. + +Next, the component contains three class members, `first`, `middle` and `last`. +Each of these class members have the [`@Prop()` decorator](../components/properties.md#the-prop-decorator-prop) applied to them: +```ts + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; +``` +`@Prop()` tells Stencil that the property is public to the component, and allows Stencil to rerender when any of these public properties change. +We'll see how this works after discussing the `render()` function. + +In order for the component to render something to the screen, we must declare a [`render()` function](../components/templating-and-jsx.md#basics) that returns JSX. +If you're not sure what JSX is, be sure to reference the [Using JSX](../components/templating-and-jsx.md) docs. + +The quick idea is that our render function needs to return a representation of the HTML we want to push to the DOM. + +```tsx + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +``` + +This component's `render()` returns a `
    ` element, containing text to render to the screen. + +The `render()` function uses all three class members decorated with `@Prop()`, through the `getText` function. +Declaring private functions like `getText` helps pull logic out of the `render()` function's JSX. + +Any property decorated with `@Prop()` is also automatically watched for changes. +If a user of our component were to change the element's `first`, `middle`, or `last` properties, our component would fire its `render()` function again, updating the displayed content. + +## Updating Stencil + +To get the latest version of @stencil/core you can run: + +```bash npm2yarn +npm install @stencil/core@latest --save-exact +``` diff --git a/versioned_docs/version-v4.19/introduction/_category_.json b/versioned_docs/version-v4.19/introduction/_category_.json new file mode 100644 index 000000000..fa1c06ac8 --- /dev/null +++ b/versioned_docs/version-v4.19/introduction/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Introduction", + "position": 1 +} diff --git a/versioned_docs/version-v4.19/introduction/upgrading-to-stencil-four.md b/versioned_docs/version-v4.19/introduction/upgrading-to-stencil-four.md new file mode 100644 index 000000000..56b492853 --- /dev/null +++ b/versioned_docs/version-v4.19/introduction/upgrading-to-stencil-four.md @@ -0,0 +1,257 @@ +--- +title: Upgrading to Stencil v4.0.0 +description: Upgrading to Stencil v4.0.0 +url: /docs/upgrading-to-stencil-4 +--- + +# Upgrading to Stencil v4.0.0 + +## Getting Started + +We recommend that you only upgrade to Stencil v4 from Stencil v3. +If you're a few versions behind, we recommend upgrading one major version at a time (from v1 to v2, then v2 to v3, finally v3 to v4). +This will minimize the number of breaking changes you have to deal with at the same time. + +For breaking changes introduced in previous major versions of the library, see: +- [Stencil v3 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v300) +- [Stencil v2 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-two) +- [Stencil v1 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-one) + +For projects that are on Stencil v3, install the latest version of Stencil v4: `npm install @stencil/core@4` + + +## Updating Your Code + +### New Configuration Defaults +Starting with Stencil v4.0.0, the default configuration values have changed for a few configuration options. +The following sections lay out the configuration options that have changed, their new default values, and ways to opt-out of the new behavior (if applicable). + +#### `transformAliasedImportPaths` + +TypeScript projects have the ability to specify a path aliases via the [`paths` configuration in their `tsconfig.json`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) like so: +```json title="tsconfig.json" +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@utils": ["src/utils/index.ts"] + } + } +} +``` +In the example above, `"@utils"` would be mapped to the string `"src/utils/index.ts"` when TypeScript performs type resolution. +The TypeScript compiler does not however, transform these paths from their keys to their values as a part of its output. +Instead, it relies on a bundler/loader to do the transformation. + +The ability to transform path aliases was introduced in [Stencil v3.1.0](https://github.com/ionic-team/stencil/releases/tag/v3.1.0) as an opt-in feature. +Previously, users had to explicitly enable this functionality in their `stencil.config.ts` file with `transformAliasedImportPaths`: +```ts title="stencil.config.ts - enabling 'transformAliasedImportPaths' in Stencil v3.1.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: true, + // ... +}; +``` + +Starting with Stencil v4.0.0, this feature is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v3.1.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPaths' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: false, + // ... +}; +``` + +For more information on this flag, please see the [configuration documentation](../config/01-overview.md#transformaliasedimportpaths) + +#### `transformAliasedImportPathsInCollection` + +Introduced in [Stencil v2.18.0](https://github.com/ionic-team/stencil/releases/tag/v2.18.0), `transformAliasedImportPathsInCollection` is a configuration flag on the [`dist` output target](../output-targets/dist.md#transformaliasedimportpathsincollection). +`transformAliasedImportPathsInCollection` transforms import paths, similar to [`transformAliasedImportPaths`](#transformaliasedimportpaths). +This flag however, only enables the functionality of `transformAliasedImportPaths` for collection output targets. + +Starting with Stencil v4.0.0, this flag is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v2.18.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPathsInCollection' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist', + transformAliasedImportPathsInCollection: false, + }, + // ... + ] + // ... +}; +``` + +For more information on this flag, please see the [`dist` output target's documentation](../output-targets/dist.md#transformaliasedimportpathsincollection). + +### In Browser Compilation Support Removed + +Prior to Stencil v4.0.0, components could be compiled from TSX to JS in the browser. +This feature was seldom used, and has been removed from Stencil. +At this time, there is no replacement functionality. +For additional details, please see the [request-for-comment](https://github.com/ionic-team/stencil/discussions/4134) on the Stencil GitHub Discussions page. + +### Legacy Context and Connect APIs Removed + +Previously, Stencil supported `context` and `connect` as options within the `@Prop` decorator. +Both of these APIs were deprecated in Stencil v1 and are now removed. + +```ts +@Prop({ context: 'config' }) config: Config; +@Prop({ connect: 'ion-menu-controller' }) lazyMenuCtrl: Lazy; +``` +To migrate away from usages of `context`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propcontext). +To migrate away from usages of `connect`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propconnect). + +### Legacy Browser Support Removed + +In Stencil v3.0.0, we announced [the deprecation of IE 11, pre-Chromium Edge, and Safari 10 support](https://github.com/ionic-team/stencil/blob/1a8ff39073a88d1372beaa98434dbe2247f68a85/BREAKING_CHANGES.md?plain=1#L78). +In Stencil v4.0.0, support for these browsers has been dropped (for a full list of supported browsers, please see our [Browser Support policy](../reference/support-policy.md#browser-support)). + +By dropping these browsers, a few configuration options are no longer valid in a Stencil configuration file: + +#### `__deprecated__cssVarsShim` + +The `extras.__deprecated__cssVarsShim` option caused Stencil to include a polyfill for [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/--*). +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__dynamicImportShim` + +The `extras.__deprecated__dynamicImportShim` option caused Stencil to include a polyfill for +the [dynamic `import()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) +for use at runtime. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__safari10` + +The `extras.__deprecated__safari10` option would patch ES module support for Safari 10. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__shadowDomShim` + +The `extras.__deprecated__shadowDomShim` option would check whether a shim for [shadow +DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) +was needed in the current browser, and include one if so. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Legacy Cache Stats Config Flag Removed + +The `enableCacheStats` flag was used in legacy behavior for caching, but has not been used for some time. This +flag has been removed from Stencil's API and should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Drop Node 14 Support + +Stencil no longer supports Node 14. +Please upgrade local development machines, continuous integration pipelines, etc. to use Node v16 or higher. +For the full list of supported runtimes, please see [our Support Policy](../reference/support-policy.md#javascript-runtime). + +## Information Included in `docs-json` Expanded + +For Stencil v4 the information included in the output of the `docs-json` output +target was expanded to include more information about the types of properties +and methods on Stencil components. + +For more context on this change, see the [documentation for the new `supplementalPublicTypes`](../documentation-generation/docs-json.md#supplementalpublictypes) +option for the JSON documentation output target. + +### `JsonDocsEvent` + +The JSON-formatted documentation for an `@Event` now includes a field called +`complexType` which includes more information about the types referenced in the +type declarations for that property. + +Here's an example of what this looks like for the [ionBreakpointDidChange +event](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/modal/modal.tsx#L289-L292) +on the `Modal` component in Ionic Framework: + +```json +{ + "complexType": { + "original": "ModalBreakpointChangeEventDetail", + "resolved": "ModalBreakpointChangeEventDetail", + "references": { + "ModalBreakpointChangeEventDetail": { + "location": "import", + "path": "./modal-interface", + "id": "src/components/modal/modal.tsx::ModalBreakpointChangeEventDetail" + } + } + } +} +``` + +### `JsonDocsMethod` + +The JSON-formatted documentation for a `@Method` now includes a field called +`complexType` which includes more information about the types referenced in +the type declarations for that property. + +Here's an example of what this looks like for the [open +method](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/select/select.tsx#L261-L313) +on the `Select` component in Ionic Framework: + +```json +{ + "complexType": { + "signature": "(event?: UIEvent) => Promise", + "parameters": [ + { + "tags": [ + { + "name": "param", + "text": "event The user interface event that called the open." + } + ], + "text": "The user interface event that called the open." + } + ], + "references": { + "Promise": { + "location": "global", + "id": "global::Promise" + }, + "UIEvent": { + "location": "global", + "id": "global::UIEvent" + }, + "HTMLElement": { + "location": "global", + "id": "global::HTMLElement" + } + }, + "return": "Promise" + } +} +``` + +## Additional Packages + +To ensure the proper functioning of other `@stencil/` packages, it is advisable for projects utilizing any of the packages mentioned below to upgrade to the minimum package version specified. + +| Package | Minimum Package Version | GitHub | Documentation | +|----------------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|-------------------------------------------------------------| +| `@stencil/angular-output-target` | [0.7.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fangular-output-target%400.7.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/angular.md) | +| `@stencil/sass` | [3.0.4](https://github.com/ionic-team/stencil-sass/releases/tag/v3.0.4) | [GitHub](https://github.com/ionic-team/stencil-sass) | [GitHub README](https://github.com/ionic-team/stencil-sass) | +| `@stencil/store` | [2.0.8](https://github.com/ionic-team/stencil-store/releases/tag/v2.0.8) | [GitHub](https://github.com/ionic-team/stencil-store) | [Stencil Doc Site](../guides/store.md) | +| `@stencil/react-output-target` | [0.5.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Freact-output-target%400.5.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/react.md) | +| `@stencil/vue-output-target` | [0.8.6](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fvue-output-target%400.8.6) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/vue.md) | + +## Need Help Upgrading? + +Be sure to look at the Stencil [v4.0.0 Breaking Changes Guide](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v400). + +If you need help upgrading, please post a thread on the [Stencil Discord](https://chat.stenciljs.com). diff --git a/versioned_docs/version-v4.19/output-targets/01-overview.md b/versioned_docs/version-v4.19/output-targets/01-overview.md new file mode 100644 index 000000000..550880879 --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/01-overview.md @@ -0,0 +1,68 @@ +--- +title: Stencil Output Targets +sidebar_label: Overview +description: Stencil Output Targets +slug: /output-targets +--- + +# Output Targets + +One of the more powerful features of the compiler is its ability to generate various builds depending on _"how"_ the components are going to be used. Stencil is able to take an app's source and compile it to numerous targets, such as a webapp to be deployed on an http server, as a third-party component lazy-loaded library to be distributed on [npm](https://www.npmjs.com/), or a vanilla custom elements bundle. By default, Stencil apps have an output target type of `www`, which is best suited for a webapp. + + +## Output Target Types: + - [`dist`: Distribution](./dist.md) + - [`www`: Website](./www.md) + - [`dist-custom-elements`: Custom Elements](./custom-elements.md) + +## Example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist' + }, + { + type: 'www' + } + ] +}; +``` + +## Primary Package Output Target Validation + +If `validatePrimaryPackageOutputTarget: true` is set in your project's [Stencil config](../config/01-overview.md#validateprimarypackageoutputtarget) Stencil will +attempt to validate certain fields in your `package.json` that correspond with the generated distribution code. Because Stencil can output many different formats +from a single project, it can only validate that the `package.json` has field values that align with one of the specified output targets in your project's config. +So, Stencil allows you to designate which output target should be used for this validation and thus which will be the default distribution when bundling your +project. + +This behavior only affects a small subset of output targets so a flag exists on the following targets that are eligible for this level of validation: `dist`, `dist-types`, +`dist-collection`, and `dist-custom-elements`. For any of these output targets, you can configure the target to be validated as follows: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + outputTargets: [ + { + type: 'dist', + // This flag is what tells Stencil to use this target for validation + isPrimaryPackageOutputTarget: true, + ... + }, + ... + ], + // If this is not set, Stencil will not validate any targets + validatePrimaryPackageOutputTarget: true, +}; +``` + +:::note +Stencil can only validate one of these output targets for your build. If multiple output targets are marked for validation, Stencil will use +the first designated target in the array and ignore all others. +::: diff --git a/versioned_docs/version-v4.19/output-targets/_category_.json b/versioned_docs/version-v4.19/output-targets/_category_.json new file mode 100644 index 000000000..ae7d15137 --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Output Targets", + "position": 6 +} diff --git a/versioned_docs/version-v4.19/output-targets/copy-tasks.md b/versioned_docs/version-v4.19/output-targets/copy-tasks.md new file mode 100644 index 000000000..1e2d5eaa5 --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/copy-tasks.md @@ -0,0 +1,152 @@ +--- +title: Stencil Copy Tasks +sidebar_label: Copy Tasks +description: Stencil Copy Tasks +slug: /copy-tasks +--- + + +# Copy Tasks for Output Targets + +All of Stencil's non-documentation output targets +([`dist-custom-elements`](./custom-elements.md), [`dist`](./dist.md), and +[`www`](./www.md)) support a `copy` config which allows you to define file copy +operations which Stencil will automatically perform as part of the build. This +could be useful if, for instance, you had some static assets like images which +should be distributed alongside your components. + +The `copy` attribute on these output targets expects an array of objects corresponding to the following `CopyTask` interface: + +```ts reference title="CopyTask" +https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 +``` + +## Options + +A copy task can take the following options: + +#### `src` + +The source file path for a copy operation. This may be an absolute or relative path to a directory or a file, and may also include a glob pattern. + +If the path is a relative path it will be treated as relative to `Config.srcDir`. + +__Type:__ `string` + +#### `dest` + +An optional destination file path for a copy operation. This may be an absolute or relative path. + +If relative, this will be treated as relative to the output directory for the output target for which this copy operation is configured. + +__Type:__ `string` + +#### `warn` + +Whether or not Stencil should issue warnings if it cannot find the specified source files or directories. Defaults to `false`. + +To receive warnings if a copy task source can't be found set this to `true`. + +__Type:__ `boolean` + +#### `keepDirStructure` + +Whether or not directory structure should be preserved when copying files from a source directory. Defaults to `true` if no `dest` path is supplied, else it defaults to `false`. + +If this is set to `false`, all the files from a source directory will be copied directly to the destination directory, but if it's set to `true` they will be copied to a new directory inside the destination directory with the same name as their original source directory. + +So if, for instance, `src` is set to `"images"` and `keepDirStructure` is set to `true` the copy task will then produce the following directory structure: + +``` +images +└── foo.png +dist +└── images + └── foo.png +``` + +Conversely if `keepDirStructure` is set to `false` then files in `images/` will be copied to `dist` without first creating a new subdirectory, resulting in the following directory structure: + +``` +images +└── foo.png +dist +└── foo.png +``` + +If a `dest` path is supplied then `keepDirStructure` will default to `false`, so that Stencil will write the copied files directly into the `dest` directory without creating a new subdirectory. This behavior can be overridden by setting `keepDirStructure` to `true`. + +## Examples + +### Images in the `www` Output Target + +The `copy` config within the following [`www` output target](./www.md) config +will cause Stencil to copy the entire directory from `src/images` to +`www/images`: + +```tsx + outputTargets: [ + { + type: 'www', + copy: [ + { src: 'images' } + ] + } + ] +``` + +In this example, since the `srcDir` property is not set, the default source +directory is `src/`, and since `dest` is not set the contents of `src/images` +will be copied to a new `images` directory in `www`, the default destination +directory for the `www` Output Target. + + +### Setting the `dest` option + +The `dest` property can also be optionally set on a `CopyTask` to either an +absolute path or a path relative to the build directory of the output target. + +In this example we've customized the build directory to be `public` instead of +the default (`'www'`), which, in combination with `dest: 'static/web-fonts'` +will copy the contents of `src/files/fonts` over to `public/static/web-fonts`: + +```tsx + outputTargets: [ + { + type: 'www', + dir: 'public', + copy: [ + { src: 'files/fonts', dest: 'static/web-fonts' } + ] + } + ] +``` + +:::note +When `dest` is set on a `CopyTask` Stencil will, by default, copy all the contents +of the `src` directory to the `dest` directory without creating a new +subdirectory for the contents of `src`. The `keepDirStructure` option can +control this behavior. If it's set to `true` Stencil will always create a +new subdirectory within `dest` with the same name as the `src` directory. In the +above example this would result in the contents of `src/files/fonts` being copied +to `public/static/web-fonts/fonts` instead of `public/static/web-fonts`. + +See the above documentation for the `keepDirStructure` option for more details. +::: + +### Opting-in to warnings + +By default, Stencil will not log a warning if a file or directory specified in +`src` cannot be located. To opt-in to warnings if a copy task source cannot be +found, set `warn: true` in the `CopyTask` object, like so: + +```tsx + outputTargets: [ + { + type: 'dist', + copy: [ + { src: 'fonts', warn: true } + ] + } + ] +``` diff --git a/versioned_docs/version-v4.19/output-targets/custom-elements.md b/versioned_docs/version-v4.19/output-targets/custom-elements.md new file mode 100644 index 000000000..b6fed7bbe --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/custom-elements.md @@ -0,0 +1,236 @@ +--- +title: Custom Elements with Stencil +sidebar_label: dist-custom-elements +description: Custom Elements with Stencil +slug: /custom-elements +--- + +# Custom Elements + +The `dist-custom-elements` output target creates custom elements that directly extend `HTMLElement` and provides simple utility functions for easily defining these elements on the [Custom Element Registry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry). This output target excels in use in frontend frameworks and projects that will handle bundling, lazy-loading, and custom element registration themselves. + +This target can be used outside of frameworks as well, if lazy-loading functionality is not required or desired. For using lazily loaded Stencil components, please refer to the [dist output target](./dist.md). + +To generate components using the `dist-custom-elements` output target, add it to a project's `stencil.config.ts` file like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + // Other top-level config options here + outputTargets: [ + { + type: 'dist-custom-elements', + // Output target config options here + }, + // Other output targets here + ], +}; +``` + +## Config + +### copy + +_default: `undefined`_ + +An array of [copy tasks](./copy-tasks.md) to be executed during the build process. + +### customElementsExportBehavior + +_default: `'default'`_ + +By default, the `dist-custom-elements` output target generates a single file per component, and exports each of those files individually. + +In some cases, library authors may want to change this behavior, for instance to automatically define component children, provide a single file containing all component exports, etc. + +This config option provides additional behaviors that will alter the default component export _OR_ custom element definition behaviors +for this target. The desired behavior can be set via the following in a project's Stencil config: + +```ts +// stencil.config.ts +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + customElementsExportBehavior: 'default' | 'auto-define-custom-elements' | 'bundle' | 'single-export-module', + }, + // ... + ], + // ... +}; +``` + +| Option | Description | +| ----------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `default` | No additional re-export or auto-definition behavior will be performed.

    This value will be used if no explicit value is set in the config, or if a given value is not a valid option. | +| `auto-define-custom-elements` | A component and its children will be automatically defined with the `CustomElementRegistry` when the component's module is imported. | +| `bundle` | A utility `defineCustomElements()` function is exported from the `index.js` file of the output directory. This function can be used to quickly define all Stencil components in a project on the custom elements registry. | +| `single-export-module` | All component and custom element definition helper functions will be exported from the `index.js` file in the output directory. This file can be used as the root module when distributing your component library, see [Publishing](/publishing) for more details. | + +:::note +At this time, components that do not use JSX cannot be automatically +defined. This is a known limitation of Stencil that users should be aware of. +::: + +### dir + +_default: `'dist/components'`_ + +This config option allows you to change the output directory where the compiled output for this output target will be written. + +### empty + +_default: `true`_ + +Setting this flag to `true` will remove the contents of the [output directory](#dir) between builds. + +### externalRuntime + +_default: `true`_ + +Setting this flag to `true` results in the following behaviors: + +1. Minification will follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). +2. Filenames will not be hashed. +3. All imports from packages under `@stencil/core/*` will be marked as external and therefore not included in the generated Rollup bundle. + +Ensure that `@stencil/core` is included in your list of dependencies if you set this option to `true`. This is crucial to prevent any runtime errors. + +### generateTypeDeclarations + +_default: `true`_ + +By default, Stencil will generate type declaration files (`.d.ts` files) as a part of the `dist-custom-elements` output target through the `generateTypeDeclarations` field on the target options. Type declaration files will be placed in the `dist/types` directory in the root of a Stencil project. At this time, this output destination is not able to be configured. + +Setting this flag to `false` will not generate type declaration files for the `dist-custom-elements` output target. + +:::note +When set to generate type declarations, Stencil respects the export behavior selected via `customElementsExportBehavior` and generates type declarations specific to the content of the generated [output directory's](#dir) `index.js` file. +::: + +### includeGlobalScripts + +_default: `false`_ + +Setting this flag to `true` will include [global scripts](../config/01-overview.md#globalscript) in the bundle and execute them once the bundle entry point in loaded. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### minify + +_default: `false`_ + +Setting this flag to `true` will cause file minification to follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). _However_, if [`externalRuntime`](#externalruntime) is enabled, it will override this option and always result in minification being disabled. + +## Making Assets Available + +For performance reasons, the generated bundle does not include [local assets](../guides/assets.md) built within the JavaScript output, +but instead it's recommended to keep static assets as external files. By keeping them external this ensures they can be requested on-demand, rather +than either welding their content into the JS file, or adding many URLs for the bundler to add to the output. +One method to ensure [assets](../guides/assets.md) are available to external builds and http servers is to set the asset path using `setAssetPath()`. + +The `setAssetPath()` function is used to manually set the base path where static assets can be found. +For the lazy-loaded output target the asset path is automatically set and assets copied to the correct +build directory. However, for custom elements builds, the `setAssetPath(path)` should be +used to customize the asset path depending on where they are found on the http server. + +If the component's script is a `type="module"`, it's recommended to use `import.meta.url`, such +as `setAssetPath(import.meta.url)`. Other options include `setAssetPath(document.currentScript.src)`, or using a bundler's replace plugin to +dynamically set the path at build time, such as `setAssetPath(process.env.ASSET_PATH)`. + +```tsx +import { setAssetPath } from 'my-library/dist/components'; + +setAssetPath(document.currentScript.src); +``` + +Make sure to copy the assets over to a public directory in your app. This configuration depends on how your script is bundled, or lack of +bundling, and where your assets can be loaded from. How the files are copied to the production build directory depends on the bundler or tooling. +The configs below provide examples of how to do this automatically with popular bundlers. + +## Example Bundler Configs + +Instructions for consuming the custom elements bundle vary depending on the bundler you're using. These examples will help your users consume your components with webpack and Rollup. + +The following examples assume your component library is published to NPM as `my-library`. You should change this to the name you actually publish your library with. + +Users will need to install your library before importing them. + +```bash npm2yarn +npm install my-library +``` + +### webpack.config.js + +A webpack config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `CopyPlugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); + +module.exports = { + entry: './src/index.js', + output: { + filename: 'main.js', + path: path.resolve(__dirname, 'dist'), + }, + module: { + rules: [ + { + test: /\.css$/i, + use: ['style-loader', 'css-loader'], + }, + ], + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + to: path.resolve(__dirname, 'dist/assets'), + }, + ], + }), + ], +}; +``` + +### rollup.config.js + +A Rollup config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `rollup-copy-plugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +import path from 'path'; +import commonjs from '@rollup/plugin-commonjs'; +import copy from 'rollup-plugin-copy'; +import postcss from 'rollup-plugin-postcss'; +import resolve from '@rollup/plugin-node-resolve'; + +export default { + input: 'src/index.js', + output: [{ dir: path.resolve('dist/'), format: 'es' }], + plugins: [ + resolve(), + commonjs(), + postcss({ + extensions: ['.css'], + }), + copy({ + targets: [ + { + src: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + dest: path.resolve(__dirname, 'dist'), + }, + ], + }), + ], +}; +``` diff --git a/versioned_docs/version-v4.19/output-targets/dist.md b/versioned_docs/version-v4.19/output-targets/dist.md new file mode 100644 index 000000000..5c33af5d2 --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/dist.md @@ -0,0 +1,106 @@ +--- +title: Distributing Web Components Built with Stencil +sidebar_label: dist +description: Distributing Web Components Built with Stencil +slug: /distribution +--- + +# Distribution Output Target + +The `dist` type is to generate the component(s) as a reusable library that can be self-lazy loading, such as [Ionic](https://www.npmjs.com/package/@ionic/core). When creating a distribution, the project's `package.json` will also have to be updated. However, the generated bundle is tree-shakable, ensuring that only imported components will end up in the build. + +```tsx +outputTargets: [ + { + type: 'dist' + } +] +``` + +## Config + +### collectionDir + +The `collectionDir` config specifies the output directory within the [distribution directory](#dir) where the transpiled output of Stencil components will be written. + +This option defaults to `collection` when omitted from a Stencil configuration file. + +### dir + +The `dir` config specifies the public distribution directory. This directory is commonly the `dist` directory found within [npm packages](https://docs.npmjs.com/getting-started/packages). This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended that this directory not be committed to a repository. + +This option defaults to `dist` when omitted from a Stencil configuration file. + +### empty + +By default, before each build the `dir` directory will be emptied of all files. To prevent this directory from being emptied, change this value to `false`. + +This flag defaults to `true` when omitted from a Stencil configuration file. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### transformAliasedImportPathsInCollection + +*default: `true`* + +This option will allow [path aliases](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in a project's `tsconfig.json` to be transformed into relative paths in the code output under the [collectionDir](#collectiondir) subdirectory for this output target. This does not affect imports for external packages. + +An example of path transformation could look something like: + +```ts +// Source code +import * as utils from '@utils'; + +// Output code +import * as utils from '../path/to/utils'; +``` + +:::tip +If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config. +::: + +### esmLoaderPath + +*default: `/dist/loader`* + +Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading. Read more about the loader directory in the [section below](#loader). + +If you don't use a custom [exports](https://nodejs.org/api/packages.html#exports) map, users would have to import the loader script via: + +```js +import { defineCustomElements } from 'stencil-library/dist/loader' +``` + +By setting `esmLoaderPath` to e.g. `../loader` you can shorten or rename the import path to: + +```js +import { defineCustomElements } from 'stencil-library/loader' +``` + +## Publishing + +Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md). + +## Loader + +The `dist` output target generates a loader directory that exports `setNonce`, `applyPolyfills` and `defineCustomElements` helper functions when imported within an ESM context. This allows you to register all components of your library to be used in your project in an application setup script, e.g.: + +```ts +import { applyPolyfills, defineCustomElements, setNonce } from 'stencil-library/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +applyPolyfills().then(() => { + defineCustomElements(); +}); +``` + +This is an alternative approach to e.g. loading the components directly through a script tag as mentioned below. Read more about `setNonce` and when to set it in our guide on [Content Security Policy Nonces](../guides/csp-nonce.md). diff --git a/versioned_docs/version-v4.19/output-targets/www.md b/versioned_docs/version-v4.19/output-targets/www.md new file mode 100644 index 000000000..6c3079364 --- /dev/null +++ b/versioned_docs/version-v4.19/output-targets/www.md @@ -0,0 +1,32 @@ +--- +title: Webapp Output Target +sidebar_label: www +description: Webapp Output Target +slug: /www +--- + +# Webapp Output Target: `www` + +The `www` output target type is oriented for webapps and websites, hosted from an http server, which can benefit from prerendering and service workers, such as this very site you're reading. If the `outputTarget` config is not provided it'll default to having just the `www` type. + +Even if a project is meant to only build a reusable component library, the `www` output target is useful to build out and test the components throughout development. + +```tsx +outputTargets: [ + { + type: 'www' + } +] +``` + +## Config + +| Property | Description | Default | +|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| +| `baseUrl` | The `baseUrl` represents the site's "base" url to be served from. For example, this site's base url is `https://stenciljs.com/`. However, if the entire site's output is to live within a sub directory, then this directory's path should be the `baseUrl`. For example, Ionic's documentation is a stand-alone Stencil site that lives in the `/docs` directory within `https://ionicframework.com/`. In this example, `https://ionicframework.com/docs/` would be the base url. | `/` | +| `buildDir` | The `buildDir` is the directory of Stencil's generated scripts, such as the component files. For production builds, this directory will contain both `es5` and `esm` builds for each component. (Don't worry, users only request the one their browser needs.) | `build` | +| `dir` | The `dir` config specifies the public web distribution directory. This directory is commonly the root directory of an app to be served, such as serving static files from. This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended this directory is not committed to a repository. | `www` | +| `empty` | By default, before each build the `dir` directory will be emptied of all files. However, to prevent this directory from being emptied change this value to `false`. | `true` | +| `indexHtml` | The `indexHtml` property represents the location of the root index html file. | `index.html` | +| `serviceWorker` | The `serviceWorker` config lets you customize the service worker that gets automatically generated by the Stencil compiler. To override Stencil's defaults, set any of the values listed in the [Workbox documentation](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). + diff --git a/versioned_docs/version-v4.19/reference/_category_.json b/versioned_docs/version-v4.19/reference/_category_.json new file mode 100644 index 000000000..75879876e --- /dev/null +++ b/versioned_docs/version-v4.19/reference/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Reference", + "position": 10 +} diff --git a/versioned_docs/version-v4.19/reference/faq.md b/versioned_docs/version-v4.19/reference/faq.md new file mode 100644 index 000000000..eab0321a9 --- /dev/null +++ b/versioned_docs/version-v4.19/reference/faq.md @@ -0,0 +1,192 @@ +--- +title: Stencil Frequently Asked Questions +sidebar_label: FAQ +description: Stencil is a developer-focused toolchain for building reusable, scalable component libraries. +slug: /faq +--- + +# FAQ + +## Introduction + +### What is Stencil? + +Stencil is a developer-focused toolchain for building reusable, scalable component libraries. It provides a compiler that generates highly optimized Web Components, and combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil focuses on building components with web standards. It’s used by developers and organizations around the world, and is [100% free and MIT open source](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### What does Stencil do? + +Stencil helps developers and teams build and share custom components. Since Stencil generates standards-compliant Web Components, the components you build with Stencil will work with many popular frameworks right out of the box, and can even be used without a framework because they are just Web Components. Stencil also enables a number of key capabilities on top of Web Components, in particular, prerendering, and objects-as-properties (instead of just strings). + + +### Who is Stencil for? + +Stencil is for developers and teams that want to build custom component libraries that can be shared across teams, frameworks and large organizations. + +Stencil can also be used by designers who want their original design visions delivered consistently, with high fidelity, to all users. + + +### Who makes Stencil? + +Stencil is an open source project started by the [Ionic core team](https://ionicframework.com/), with contributions also coming from the community. + + +### Why was Stencil created? + +Stencil was created by the Ionic Framework team to make our own component library faster, smaller, and compatible with all major frameworks. Web Components offered a solution by pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + + +### Who uses Stencil? + +Stencil was initially developed for Ionic Framework which is a very successful Web Component-based library & UI framework. Web Components are now in thousands of app store apps, and nearly 4 million new Ionic Framework projects are being created every year. + + +### How does Stencil compare to traditional frameworks? + +The Web Component ecosystem has a diverse set of players, each with a different long-term vision for what Web Components can and should do. + +Some think Web Components should replace third-party app frameworks, while others think that Web Components are more suited for leaf/style/design nodes and shouldn’t get in the business of your app’s component system. There are also many framework developers that don’t see the point of Web Components, or consider them to be an affront to front-end innovation. + +With Stencil, our vision is somewhere in the middle. In the long term, we see app development teams continuing to use their framework of choice. We envision these frameworks continuing to get better, smaller, and more efficient, with increasingly good support for targeting and consuming Web Components -- and big teams will be consuming an increasing amount of Web Components as companies continue to embrace them for shared component libraries. + +At the same time, we believe an indispensable feature for Web Components is solving those component distribution and design system problems. We also believe, however, that 90% of the market doesn’t have those problems to begin with, so the current debate about the merits of Web Components is somewhat unproductive. + + +### Why is Stencil considered framework-agnostic? + +Perhaps the most appealing benefit of Web Components is that they give your development teams the flexibility to choose the underlying tools and frameworks - and versions of those frameworks - and tools that they prefer. As pointed out earlier, one of the great challenges of implementing a universal set of components is getting all of your development teams to standardize on just one set of technologies. With Web Components, each team can use what works best for them, giving them complete freedom to use the tools they love—today and tomorrow. + + +## What does Stencil provide? + +### Does Stencil have a component library? + +The most widely used Stencil component library is the Ionic Framework, however, Stencil itself is only a toolchain and does not provide its own component library. We encourage you to first review Ionic components if you are building an application. + + +### Is Stencil a framework? + +Stencil purposely does not strive to act as a stand-alone framework, but rather a tool which allows developers to scale framework-agnostic components across many projects, teams and large organizations. One of Stencil’s superpowers is its flexibility: its components could be used stand-alone, or within traditional frameworks. + + +### Does Stencil come with a testing framework? + +Yes, Stencil provides a rich set of APIs for unit and End-to-end tests. [Learn more about testing with Stencil](../testing/01-overview.md). + + + +## Technology + + +### Why does Stencil use web components? + +By using a consistent set of web standards, Web Components do not depend on a specific framework runtime to execute. As frameworks change their APIs, Web Components do not, allowing for the original source to continue to work natively in a browser. + + +### How is Stencil able to optimize component file size and startup? + +Traditional frameworks provide a runtime API, and developers can pick and choose which APIs to use per component. However, this means every feature needs to be available to every component, just in case the component may or may not use the API. + +With Stencil, the compiler is able to perform static analysis on each component in order to understand which APIs are and are not being used. By doing so, Stencil is able to customize each build to use exactly what each component needs, making for a highly optimized runtime with minimal size. + +Since Stencil uses a compiler, it is able to adjust code as new improvements and features become available. Source code can continue to be written using the same public API and syntax, while the compiler can adjust the code to further take advantage of modern features, without requiring re-writes. + + +### What template syntax does Stencil use? + +Stencil uses [JSX](https://react.dev/learn/writing-markup-with-jsx), a markup language popularized by the React library. + + +### Can Stencil components be lazy loaded? + +Yes! Lazy loading components helps to reduce application startup times, decrease bundle sizes, and improve distribution. + +Because users are able to dynamically load only what is used, startup times are drastically reduced and users only load exactly what their application’s first paint requires. + +At the same time, components built with Stencil can still be imported and consumed by traditional bundlers. + + +### Why are Stencil components written with TypeScript? + +Stencil was originally built for Ionic, and in our experience we’ve found TypeScript to be a valuable tool for maintaining a large codebase across multiple teams. + + +### What dependencies does the Stencil runtime have? + +None. The code generated by Stencil does not rely on Stencil, but rather it generates highly-optimized, framework-free, stand-alone code which runs natively in the browser. + + +### Can data be passed to Web Components? + +Just like any other DOM element in a webpage, any data in the form of arrays, objects, strings and numbers can be passed to element properties. Stencil is designed from the ground up to ensure this capability stays unlocked for application developers. + + +### What technology is Stencil built with? + +The Stencil compiler is built with TypeScript and is [distributed on npm](https://www.npmjs.com/package/@stencil/core). Its distribution includes types, making it easier for developers to use Stencil APIs. + + +## Capabilities + +### Where can Stencil components be used? + +One great advantage of using Web Components is that your component library will work across all projects, not just desktop web apps. + +For example, using a hybrid mobile framework like Ionic, you can deploy Web Components across just about any platform or device, from native iOS and Android apps, to Electron and desktop web apps, and even Progressive Web Apps. + + +### What are the limitations of Web Components? + +The [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) specs are purposely low-level, and on their own, they do not provide a framework quality developer experience. Web Components run on a fairly primitive set of standards, so you will need a little help to get them to meet your objectives. + +Some limitations include: + +When you try to use pure vanilla Web Components in an application, functionality like server-side rendering and progressive enhancement is not supported by default, and +some out-of-date clients don’t support the Web Components standard. + +In addition, while Web Components technically work with any framework, there are some limitations like lack of type support and input bindings, and challenges passing properties to components, as noted above. + +The good news is that, with help from open source tools like Stencil, you can overcome all of these challenges. Stencil includes framework bindings for Angular, React, and Vue, so you can easily import Web Component libraries into any framework, and interact with them just like they were native to that framework, with all the functionality you’re used to. + + +### What are framework bindings? + +While Web Components can be paired with any JavaScript framework, Stencil has built-in special-purpose bindings to deliver the more advanced features enterprise teams expect when building applications in Angular, React, and Vue. + + +### What features does Stencil add to Web Components? + +Web Components by themselves weren't enough to provide a quality development experience. Building fast web apps required innovations that were previously locked up inside traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. + +Compared to using Web Components directly, Stencil provides extra APIs that make writing fast components simpler. APIs like Virtual DOM, JSX, and async rendering make fast, powerful components easy to create, while still maintaining 100% compatibility with Web Components. + + +### What browsers can support Stencil components? + +Stencil works on modern browsers. + +[Learn more about browser support](./support-policy.md#browser-support). + + +## Stencil Project + +### How do I get involved? + +Stencil is an open source project, and we encourage you to contribute. You can start by creating issues on GitHub, submitting feature requests, and helping to replicate bugs. If you’re interested in contributing, please see our [Contributor Guide](https://github.com/ionic-team/stencil/blob/main/.github/CONTRIBUTING.md) and check out our [issue tracker](https://github.com/ionic-team/stencil/issues). + + +### Is Stencil open source? + +Yes, Stencil is open source and its source code can be [found on GitHub](https://github.com/ionic-team/stencil). Contributions are welcomed from the community. + +### Which software license does Stencil use? + +Stencil’s software [license is MIT](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### Who works on Stencil? + +The majority of the development is done by engineers at [Ionic](https://github.com/ionic-team/ionic). If you’re excited about Stencil, we encourage you to join the community and contribute! Best place to start is on the [discord channel](https://chat.stenciljs.com/). + diff --git a/versioned_docs/version-v4.19/reference/support-policy.md b/versioned_docs/version-v4.19/reference/support-policy.md new file mode 100644 index 000000000..05141a894 --- /dev/null +++ b/versioned_docs/version-v4.19/reference/support-policy.md @@ -0,0 +1,154 @@ +--- +title: Support Policy +sidebar_label: Support Policy +description: Support Policy +slug: /support-policy +--- + +# Support Policy + +## Community Maintenance + +Stencil is a 100% open source (MIT) project. Developers can ensure Stencil is the right choice for building web +components through Ionic’s community maintenance strategy. The Stencil team regularly ships new releases, bug fixes, and +is welcoming to community pull requests. + +## Stencil Maintenance and Support Status + +Given the reality of time and resource constraints as well as the desire to keep innovating in the frontend development +space, over time it becomes necessary for the Stencil team to shift focus to newer versions of the library. However, the +Stencil team will do everything it can to make the transition to newer versions as smooth as possible. The Stencil team +recommends updating to the newest version of the Stencil for the latest features, improvements and stability updates. + +The current status of each Stencil version is: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:----------------:|:------------:|:----------------:|:-----------------:| +| V4 | **Active** | Jun 26, 2023 | TBD | TBD | +| V3 | Extended Support | Jan 25, 2023 | Dec 26, 2023 | Jun 26, 2024 | +| V2 | End of Support | Aug 08, 2020 | Jul 25, 2023 | Jan 25, 2024 | +| V1 | End of Support | Jun 03, 2019 | Aug 08, 2020 | Aug 08, 2020 | + +**Maintenance Period**: Only critical bug and security fixes. No major feature improvements. + +**Extended Support Period**: Available to Stencil Enterprise customers. + +### Stencil Support Details + +Starting with Stencil v2, the Stencil team is adopting a newly revised maintenance policy. When a new major version of +Stencil is released, the previous major version release will enter maintenance mode. While a version of Stencil is in +maintenance mode, only critical bug & security fixes will be applied to that version, and no major feature improvements +will be added. The maintenance period shall last six months from the release of the new major version. + +Once the maintenance period has ended for a version of Stencil, that version enters the extended support period. During +the extended support period, only critical bug and security fixes will be applied for teams and organizations using +Stencil's Enterprise offerings. The extended support period lasts for twelve months from the release of the new major +version. + +The table below describes a theoretical timeline of releases: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:---------------------:|:------------:|:----------------:|:-----------------:| +| D | Active | Jan 01, 2022 | TBD | TBD | +| C | Maintenance | Jul 07, 2021 | Jul 01, 2022 | Jan 01, 2023 | +| B | Extended Support Only | Jan 01, 2021 | Jan 07, 2022 | Jul 07, 2022 | +| A | End of Support | Jul 07, 2020 | Jul 01, 2021 | Jan 01, 2021 | + +In the example above, when Version D is released, Version C enters maintenance mode. Version D was released on January +1st, 2022. Version C shall be in maintenance mode until July 1st, 2022, three months after the release of Version D. +After July 1st 2022, Version C will be in extended support until Jun 1st, 2023, twelve months after the release of +Version D. + +## Browser Support + +Stencil builds Web Components that run natively in all widely used desktop and mobile browsers. +Custom Elements are natively supported in Chrome, Edge, Firefox, and Safari (including iOS)! + +Stencil supports the following browsers: + +| Stencil Version | Chrome | Edge | Firefox | Safari | Internet Explorer | Pre-Chromium Edge | +|:---------------:|:------:|:----:|:-------:|:------:|:-----------------:|:-----------------:| +| V4 | v79+ | v79+ | v70+ | v14+ | ❌ | ❌ | +| V3 | v79+ | v79+ | v70+ | v14+ | ✅ | ✅ | +| V2 | v60+ | v79+ | v63+ | v10.1+ | ✅ | ✅ | + +## TypeScript Support + +Stencil acts as a compiler for a project's web components, and works closely with the TypeScript compiler to transform +TSX to vanilla JavaScript. To ensure compatibility between the two, Stencil takes an opinionated stance on which version +of the TypeScript compiler must be used. + +Stencil includes a recent copy of the TypeScript compiler in its distributable* to guarantee this compatibility. +The Stencil team is committed to keeping its version of TypeScript up to date and, as of Stencil v2.10.0, attempts to be +within one minor version of the latest TypeScript release. + +The table below describes recent versions of Stencil and the version of TypeScript each version shipped with. + +| Stencil Version | TypeScript Version | +|:---------------:|:------------------:| +| v4.16.0 | v5.4.5 | +| v4.15.0 | v5.4.4 | +| v4.14.0 | v5.4.3 | +| v4.13.0 | v5.4.2 | +| v4.10.0 | v5.3.0 | +| v4.4.0 | v5.2.2 | +| v4.2.0 | v5.1.6 | +| v3.3.0 | v5.0.4 | +| v3.0.0 | v4.9.4 | +| v2.21.0 | v4.9.3 | +| v2.20.0 | v4.8.4 | +| v2.18.0 | v4.7.4 | +| v2.14.0 | v4.5.4 | +| v2.10.0 | v4.3.5 | +| v2.5.0 | v4.2.3 | +| v2.4.0 | v4.1.3 | +| v2.2.0 | v4.0.5 | + +The TypeScript team releases a new minor version of the TypeScript compiler approximately once every three months. To +accomplish its goal of staying within one minor version of the latest release, Stencil will update its version of +TypeScript once every three months as well. Updates to the version of TypeScript will often, but not always, occur in a +[minor version release](./versioning.md#minor-release) of Stencil. + +The Stencil team acknowledges that TypeScript minor version releases may contain breaking changes. The Stencil team will +do everything in its power to avoid propagating breaking changes to its user base. + +\* The TypeScript compiler is never included in the output of your Stencil project, and is only used for compilation +and type checking purposes. + +## Compatibility Recommendations + +Stencil is in many regards an opinionated library, and includes much of the software necessary to get users building web +components as quickly as possible. There are a few pieces of software that Stencil allows users to choose to best fit +their team, organizational structure, and existing technical stack. The Stencil team has compiled a series of +compatibility tables to describe the interoperability requirements of these pieces of software and Stencil. + +### JavaScript Runtime + +| Stencil Version | Node v10 | Node v12 | Node v14 | Node v16 | Node v18 | Node v20 | Node v22 | +|:---------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| +| V4 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| V3 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | +| V2 | ❌ | ✅ | ✅ | ✅ | ⚠ | ❌ | ❌ | +| V1 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | + +### Testing Libraries + +#### Jest + +| Stencil Version | Jest v24-26 | Jest v27 | Jest v28 * | Jest v29 * | +|:---------------:|:-----------:|:--------:|:----------:|:-----------:| +| V4 | ✅ | ✅ | ✅ | ✅ | +| V3 | ✅ | ✅ | ❌ | ❌ | +| V2 | ✅ | ✅ | ❌ | ❌ | +| V1 | ✅ | ❌ | ❌ | ❌ | + +\* Support for Jest 28 & 29 has been included since Stencil v4.7.0. + +#### Puppeteer + +| Stencil Version | Puppeteer v5-9 | Puppeteer v10 | Puppeteer v11-21 | +|:---------------:|:--------------:|:-------------:|:----------------:| +| V4 | ❌ | ✅ | ✅ | +| V3 | ❌ | ✅ | ✅ | +| V2 | ✅ | ✅ | ❌ | +| V1 | ✅ | ❌ | ❌ | diff --git a/versioned_docs/version-v4.19/reference/versioning.md b/versioned_docs/version-v4.19/reference/versioning.md new file mode 100644 index 000000000..09d81c7dd --- /dev/null +++ b/versioned_docs/version-v4.19/reference/versioning.md @@ -0,0 +1,44 @@ +--- +title: Versioning +sidebar_label: Versioning +description: Versioning +slug: /versioning +--- + +# Versioning + +Stencil follows the
    Semantic Versioning (SemVer) convention: +major.minor.patch. Incompatible API changes increment the major version, adding +backwards-compatible functionality increments the minor version, and backwards-compatible bug fixes +increment the patch version. + +## Release Schedule + +### Major Release + +A major release will be published when there is a breaking change introduced in the API. Major releases will occur +roughly every **6 months** and may contain breaking changes. Release candidates will be published prior to a major +release in order to get feedback before the final release. An outline of what is changing and why will be included with +the release candidates. + +### Minor Release + +A minor release will be published when a new feature is added or API changes that are non-breaking are introduced. +We will heavily test any changes so that we are confident with the release, but with new code comes the potential for +new issues*. Minor releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. + +\* This statement applies to the Stencil team upgrading its version of TypeScript as well. For more information, please +see the team's [support policy regarding TypeScript](./support-policy.md#typescript-support) + +### Patch Release + +A patch release will be published when bug fixes were included, but the API has not changed and no breaking changes were +introduced. Patch releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. There may be times where patch releases need to released more often than scheduled. + +## Changelog + +To see a list of all notable changes to Stencil, please refer to the [releases +page](https://github.com/ionic-team/stencil/releases). This contains an ordered +list of all bug fixes and new features under each release. diff --git a/versioned_docs/version-v4.19/static-site-generation/01-overview.md b/versioned_docs/version-v4.19/static-site-generation/01-overview.md new file mode 100644 index 000000000..3509f33e2 --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/01-overview.md @@ -0,0 +1,49 @@ +--- +title: Static Site Generation +sidebar_label: Overview +slug: /static-site-generation +--- + +# Static Site Generation with Stencil + +One of the best ways to build fast, interactive web sites and web apps is to utilize Static Site Generation instead of Server Side Rendering (known as SSR) or Client Side Rendering (known as Single Page Apps, or SPAs). + +Static Site Generation (SSG) means building and rendering components and routes at build time (aka prerendering) rather than server request time (SSR) or at client run-time (SPA). Because a route is already prerendered, all of the content for the route is available to search engines and clients _immediately_, so SEO and performance are maximized. + +Static Site Generation doesn't mean your pages have to be and/or _stay_ static! Stencil utilizes hydration to efficiently load client-side components at runtime to get the best of both worlds. + +Since Static Site Generation prerenders components, there are some tradeoffs and things to keep in mind, but most components can be easily prerendered without much modification. + +Stencil makes SSG easy, so read on to see how to incorporate it into your apps. + +## Benefits of Static Site Generation + +- Great [Lighthouse](https://developers.google.com/web/tools/lighthouse/) scores +- Faster time to [Largest Contentful Paint (LCP)](https://web.dev/lcp/) +- Better [Search Engine Optimization (SEO)](https://support.google.com/webmasters/answer/7451184) +- Provides functionality for users with JavaScript disabled + +## How Static Site Generation and Prerendering Works + +**Build Hydrate App**: The first step in prerendering is for the compiler to generate a "hydrate" app, which is a single directory to be used by Node.js. The "hydrate" app is automatically generated when the `--prerender` CLI flag is provided and by default the app is saved to `dist/hydrate`. Prerendering uses the hydrate app internally, however it can be used directly at a lower-level. [Learn more about the Hydrate App](../guides/hydrate-app.md) + +**Fork Prerender Tasks to Available CPUs**: Stencil can efficiently divide out the prerendering to each of the current machine's CPUs using [Node.js' Child Process API](https://nodejs.org/api/child_process.html). By tasking each CPU on the machine, the compiler can drastically speed up prerendering times. + +**Prerender Index**: After the compiler has completed the build and created child processes on each available CPU, it will then kick off the prerendering by starting at the single base URL, or the configured entry URLs. Once the page has finished prerendering it'll be written to the configured `www` directory as an `index.html` file. + +**Crawl App**: During each page prerender, Stencil also collects the anchor elements and URLs used within the page. With this information, it's able to inform the main thread of which pages should be prerendered next. The main thread is in charge of orchestrating all of the URLs, and the job is finished once all of the pages have been crawled and prerendered. + +**Deploy Static Files to Production**: Now that all of the pages have been prerendered and written as static HTML files, the `www` directory can now be deployed to a server. A significant difference from prerendering and Server-side Rendering (SSR), is that the HTTP server is just serving up static HTML files rather than dynamically generating the HTML on the server. + +**Static HTML Response**: With the static HTML files deploy to a server, visitors of each prerendered page first receive the HTML with inline styles, and no blocking JS or CSS. Additionally, the compiler is already aware of the exact modules the visitor will need for this page, and will asynchronously preload the modules using [link `modulepreload`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload). + +**Client-side Hydration**: After the HTML and inlined styles have rendered the first paint, the next step is for the same nodes within the DOM to be hydrated by the client-side JavaScript. Each component within the page will asynchronously hydrate using the initial order they were found in the DOM structure. Next, as each component lazily hydrates they're able to reuse the existing nodes found in the DOM. + +## Tooling + +To be clear, Stencil does _not_ use `Puppeteer` or `jsdom` for prerendering. Puppeteer is great for End-to-End +testing, but for performance reasons it's not ideal to quickly generate a large website with hundreds or thousands of pages. Additionally, `jsdom` is often used for unit testing, but in our experience it's difficult to use with async components and its global environment nature. + +Instead, Stencil uses its own internal DOM APIs which strictly follow the web standards, but optimized for prerendering, Static Site Generation and Server-side Rendering. By doing so, developers can still use all the same APIs they're already familiar with, but they'll seamlessly work within a NodeJS environment too. This means developers often do not have to write code differently in how they're building components, but rather they focus only on writing one type of component, and coding it using the standards they already know. To reiterate, developers do not have to learn a new API for prerendering. It's just the same web APIs your components are already using. + +Every component, machine and environment will perform differently, so it's difficult to provide a consistent benchmark. However, what we do know is that [Ionic's Documentation site](https://ionicframework.com/docs) has hundreds of pages and Stencil is able to prerender the entire site in a few seconds. diff --git a/versioned_docs/version-v4.19/static-site-generation/_category_.json b/versioned_docs/version-v4.19/static-site-generation/_category_.json new file mode 100644 index 000000000..000fe5643 --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Static Site Generation", + "position": 4 +} diff --git a/versioned_docs/version-v4.19/static-site-generation/basics.md b/versioned_docs/version-v4.19/static-site-generation/basics.md new file mode 100644 index 000000000..573c5aa52 --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/basics.md @@ -0,0 +1,72 @@ +--- +title: Static Site Generation Basics in Stencil +sidebar_label: Basics +description: Quick introduction to configuring and using Static Site Generation in Stencil +slug: /static-site-generation-basics +--- + +# Static Site Generation Basics + +Rendering components at build time (rather than purely server or client-time), can add significant performance improvements to your app, and maximize SEO impact. + +Using Static Site Generation in Stencil requires running a build command, returning promises from component lifecycle methods that fetch dynamic data, and ensuring all known URLs are properly discovered and built. + +## Static Build + +Stencil doesn't prerender components by default. However, the build can be made to prerender using the `--prerender` flag: + +```bash +stencil build --prerender +``` + +## Rendering Dynamic Data + +Many components need to render based on data fetched from a server. Stencil handles this by allowing components to return `Promise`'s from lifecycle methods like `componentWillLoad` (this can be achieved by using `async/await` as well). + +For example, this is how to have Stencil wait to render a component until it fetches data from the server: + +```typescript +async componentWillLoad() { + const ret = await fetch('https://.../api'); + + this.thing = await ret.json(); +} +``` + +## Integration with a Router + +Since Stencil will actually navigate to and execute components, it has full support for a router, including Stencil Router. + +There are no changes necessary to access route params and matches. However, make sure your routes can accept a trailing slash as prerendered static content will be treated as loading an `index.html` file at that path, and so the browser may append a trailing slash. + +In particular, if using Stencil Router, double check usage of `exact={true}` which could cause your routes to not match when loaded with a trailing slash. + +## Page and URL Discovery + +By default, Stencil crawls your app starting at base URL of `/` and discovers all paths that need to be indexed. By default this will only discover pages that are linked at build time, but can be easily configured to build any possible URL for the app. + +As each page is generated and new links are found, Stencil will continue to crawl and prerender pages. + +See the [prerender config](./prerender-config.md) docs to see how this can be customized further. + + +## Things to Watch For + +There may be some areas of your code that should absolutely not run while prerendering. To help avoid certain code Stencil provides a `Build.isBrowser` build conditional to tell prerendering to skip over. Here is an example of how to use this utility: + +```tsx +import { Build } from '@stencil/core'; + +connectedCallback() { + // Build.isBrowser is true when running in the + // browser and false when being prerendered + + if (Build.isBrowser) { + console.log('running in browser'); + } else { + console.log('running in node while prerendering'); + } +} +``` + +Also note that the actual runtime generated for the browser builds will not include code that has been excluded because of the `if (Build.isBrowser)` statement. In the above example, only `console.log('running in browser')` would be included within the component's runtime. diff --git a/versioned_docs/version-v4.19/static-site-generation/deployment.md b/versioned_docs/version-v4.19/static-site-generation/deployment.md new file mode 100644 index 000000000..b76972bcd --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/deployment.md @@ -0,0 +1,16 @@ +--- +title: Deploying a Static Site +sidebar_label: Deployment +description: Deploying a Static Site +slug: /static-site-generation-deployment +--- + +# Deploying a Stencil Static Site + +Deploying a prerendered static site built with Stencil is exactly like deploying any static site, because the output is just a set of HTML files. + +Every path that Stencil detects (or is provided using `entryUrls` in the prerender config) is generated in the `www` output target's directory, with each url given an `index.html` that becomes the root for the app. + +Think of it as turning every URL in your app into a standalone web page that bootstraps the entire app. No matter what URL a visitor comes to, they will be served an `index.html` file with that page's specific content already rendered, but with the entire app then hydrating and loading. + +This means you can simply deploy the `www` output target's directory to any static host! \ No newline at end of file diff --git a/versioned_docs/version-v4.19/static-site-generation/meta.md b/versioned_docs/version-v4.19/static-site-generation/meta.md new file mode 100644 index 000000000..606e49072 --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/meta.md @@ -0,0 +1,37 @@ +--- +title: SEO Meta Tags in SSG +sidebar_label: Meta tags +description: Managing meta tags for SEO and social media embedding in Stencil Static Sites +slug: /static-site-generation-meta-tags +--- + +# SEO Meta Tags and Static Site Generation + +Web Apps need to list detailed meta information about content in order to maximize SEO and provide good social media embed experiences. + +One of the benefits to Stencil's prerendering is that most DOM apis are available in the NodeJS environment too. +For example, to set the document title, simply run `document.title = "Page Title"`. +Similarly, meta tags can be set using standard DOM APIs as found in the browser, such as `document.head` and `document.createElement('meta')`. +For this reason, your component's runtime can take care of much of this custom work during prerendering. + +That said, the Prerender Config also includes options that allow individual pages to be modified arbitrarily during prerendering. +For example, the `afterHydrate(document, url)` hook can be used to update the parsed `document` before it is serialized into an HTML string. +The `document` argument is a [standard `Document`](https://developer.mozilla.org/en-US/docs/Web/API/Document), while the `url` argument is a [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) for the location of the page being rendered. + +In the example below, the `afterHydrate(document, url)` hook is setting the document title from url's pathname. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + afterHydrate(document, url) { + document.title = url.pathname; + } +}; +``` + +## @stencil/helmet + +The `@stencil/helmet` package was a library for managing meta tags dynamically. +It has since been deprecated. +For additional information regarding this package, please see its [GitHub page](https://github.com/ionic-team/stencil-helmet) diff --git a/versioned_docs/version-v4.19/static-site-generation/prerender-config.md b/versioned_docs/version-v4.19/static-site-generation/prerender-config.md new file mode 100644 index 000000000..c94144943 --- /dev/null +++ b/versioned_docs/version-v4.19/static-site-generation/prerender-config.md @@ -0,0 +1,106 @@ +--- +title: Prerender Config +sidebar_label: Prerender Config +description: Prerender Config +slug: /prerender-config +--- + + +# Prerender Config for Static Site Generation (SSG) + +As of `1.13.0`, the optional prerender config can be used while prerendering a `www` output target. The `prerender.config.ts` file can further update the parsed document of each page, before it is serialized to HTML. + +Within `stencil.config.ts`, set the path to the prerendering config file path using the `prerenderConfig` +property, such as: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + baseUrl: 'https://stenciljs.com/', + prerenderConfig: './prerender.config.ts', + } + ] +}; +``` + +Next, inside of the `prerender.config.ts` file, it should export a `config` object using the `PrerenderConfig` interface. + +```tsx +import { PrerenderConfig } from '@stencil/core'; +export const config: PrerenderConfig = { + ... +}; +``` + +| Config | Description | Default | +|--------|-------------|---------| +| `afterHydrate(document, url)` | Run after each `document` is hydrated, but before it is serialized into an HTML string. Hook is passed the `document` and its `URL`. | | +| `beforeHydrate(document, url)` | Run before each `document` is hydrated. Hook is passed the `document` it's `URL`. | | +| `afterSerializeTemplate(html)` | Runs after the template Document object has serialize into an HTML formatted string. Returns an HTML string to be used as the base template for all prerendered pages. | | +| `beforeSerializeTemplate(document)` | Runs before the template Document object is serialize into an HTML formatted string. Returns the Document to be serialized which will become the base template html for all prerendered pages. | | +| `canonicalUrl(url)` | A hook to be used to generate the canonical `` tag which goes in the `` of every prerendered page. Returning `null` will not add a canonical url tag to the page. | | +| `crawlUrls` | While prerendering, crawl same-origin URLs found within `` elements. | `true` | +| `entryUrls` | URLs to start the prerendering from. By default the root URL of `/` is used. | `['/']` | +| `filterAnchor(attrs, base)` | Return `true` the given `` element should be crawled or not. | | +| `filterUrl(url, base)` | Return `true` if the given URL should be prerendered or not. | | +| `filePath(url, filePath)` | Returns the file path which the prerendered HTML content should be written to. | | +| `hydrateOptions(url)` | Returns the hydrate options to use for each individual prerendered page. | | +| `loadTemplate(filePath)` | Returns the template file's content. The template is the base HTML used for all prerendered pages. | | +| `normalizeUrl(href, base)` | Used to normalize the page's URL from a given a string and the current page's base URL. Largely used when reading an anchor's `href` attribute value and normalizing it into a `URL`. | | +| `staticSite` | Static Site Generated (SSG). Does not include Stencil's client-side JavaScript, custom elements or preload modules. | `false` | +| `trailingSlash` | If the prerendered URLs should have a trailing "/"" or not | `false` | + + +## Individual Page Hydrate Options + +Beyond settings for the entire prerendering process with `prerender.config.ts`, you can also +set individual hydrate options per each page. The `hydrateOptions(url)` hook can be used to further configure each page. Below is an example of the prerender config with the `hydrateOptions()` hook, which returns options for each page. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + hydrateOptions(url) { + return { + prettyHtml: true + }; + } +}; + + +``` +| Option | Description | Default | +|--------|-------------|---------| +| `addModulePreloads` | Adds `` for modules that will eventually be requested. | `true` | +| `approximateLineWidth` | Sets an approximate line width the HTML should attempt to stay within. Note that this is "approximate", in that HTML may often not be able to be split at an exact line width. Additionally, new lines created is where HTML naturally already has whitespace, such as before an attribute or spaces between words. | `100` | +| `canonicalUrl` | Sets the `href` attribute on the `` tag within the ``. If the value is not defined it will ensure a canonical link tag is no included in the ``. | | +| `clientHydrateAnnotations` | Include the HTML comments and attributes used by the client-side JavaScript to read the structure of the HTML and rebuild each component. | `true` | +| `constrainTimeouts` | Constrain `setTimeout()` to 1ms, but still async. Also only allows `setInterval()` to fire once, also constrained to 1ms. | `true` | +| `cookie` | Sets `document.cookie`. | | +| `direction` | Sets the `dir` attribute on the top level ``. | | +| `excludeComponents` | Component tag names listed here will not be prerendered, nor will hydrated on the client-side. Components listed here will be ignored as custom elements and treated no differently than a `
    `. | | +| `inlineExternalStyleSheets` | External stylesheets from `` are instead inlined into ` + + +``` + +## Style Modes + +Component Style Modes enable you to create versatile designs for your components by utilizing different styling configurations. This is achieved by assigning the styleUrls property of a component to a collection of style mode names, each linked to their respective CSS files. + +### Example: Styling a Button Component + +Consider a basic button component that supports both iOS and Material Design aesthetics: + +```tsx title="Using style modes to style a component" +@Component({ + tag: 'simple-button', + styleUrls: { + md: './simple-button.md.css', // styles for Material Design + ios: './simple-button.ios.css' // styles for iOS + }, +}) +export class SimpleButton { + // ... +} +``` + +In the example above, two different modes are declared. One mode is named `md` (for 'Material Design') and refers back to a Material Design-specific stylesheet. Likewise, the other is named `ios` (for iOS) and references a different stylesheet for iOS-like styling. Both stylesheets are relative paths to the file that declares the component. While we have chosen short names in the above example, there's no limitation to the keys used in the `styleUrls` object. + +To dictate the style mode (Material Design or iOS) in which the button should be rendered, you must initialize the desired mode before any component rendering occurs. This can be done as follows: + +```ts +import { setMode } from '@stencil/core'; +setMode(() => 'ios'); // Setting iOS as the default mode for all components +``` + +The `setMode` function processes all elements, enabling the assignment of modes individually based on specific element attributes. For instance, by assigning the `mode` attribute to a component: + +```html + +``` + +You can conditionally set the style mode based on the `mode` property: + +```ts +import { setMode } from '@stencil/core'; + +const defaultMode = 'md'; // Default to Material Design +setMode((el) => el.getAttribute('mode') || defaultMode); +``` + +The reason for deciding which mode to apply can be very arbitrary and based on your requirements, using an element property called `mode` is just one example. + +### Important Considerations + +- __Initialization:__ Style modes must be defined at the start of the component lifecycle and cannot be changed thereafter. If you like to change the components mode dynamically you will have to re-render it entirely. +- __Usage Requirement:__ A style mode must be set to ensure the component loads with styles. Without specifying a style mode, the component will not apply any styles. +- __Input Validation:__ Verify a style mode is supported by a component you are setting it for. Setting an un-supported style mode keeps the component unstyled. +- __Querying Style Mode:__ To check the current style mode and e.g. provide different functionality based on the mode, use the `getMode` function: + +```ts +import { getMode } from '@stencil/core'; + +const simpleButton = document.queryElement('simple-button') +console.log(getMode(simpleButton)); // Outputs the current style mode of component +``` + +This approach ensures your components are adaptable and can dynamically switch between different styles, enhancing the user experience across various platforms and design preferences. + +## Global styles + +While most styles are usually scoped to each component, sometimes it's useful to have styles that are available to all the components in your project. To create styles that are globally available, start by creating a global stylesheet. For example, you can create a folder in your `src` directory called `global` and create a file called `global.css` within that. Most commonly, this file is used to declare CSS custom properties on the root element via the `:root` pseudo-class. This is because styles provided via the `:root` pseudo-class can pass through the shadow boundary. For example, you can define a primary color that all your components can use. + +```css +:root { + --color-primary: blue; +} +``` + +In addition to CSS custom properties, other use cases for a global stylesheet include + +- Theming: defining CSS variables used across the app +- Load fonts with `@font-face` +- App wide font-family +- CSS resets + +To make the global styles available to all the components in your project, the `stencil.config.ts` file comes with an optional [`globalStyle` setting](../config/01-overview.md#globalstyle) that accepts the path to your global stylesheet. + +```tsx +export const config: Config = { + namespace: 'app', + globalStyle: 'src/global/global.css', + outputTarget: [ + { + type: 'www', + }, + ], +}; +``` + +The compiler will run the same minification, autoprefixing, and plugins over `global.css` and generate an output file for the [`www`](../output-targets/www.md) and [`dist`](../output-targets/dist.md) output targets. The generated file will always have the `.css` extension and be named as the specified `namespace`. + +In the example above, since the namespace is `app`, the generated global styles file will be located at: `./www/build/app.css`. + +This file must be manually imported in the `index.html` of your application. + +```html + +``` diff --git a/versioned_docs/version-v4.20/components/templating-and-jsx.md b/versioned_docs/version-v4.20/components/templating-and-jsx.md new file mode 100644 index 000000000..43847d481 --- /dev/null +++ b/versioned_docs/version-v4.20/components/templating-and-jsx.md @@ -0,0 +1,471 @@ +--- +title: Using JSX +sidebar_label: Using JSX +description: Using JSX +slug: /templating-jsx +--- + +# Using JSX + +Stencil components are rendered using JSX, a popular, declarative template syntax. Each component has a `render` function that returns a tree of components that are rendered to the DOM at runtime. + +## Basics + +The `render` function is used to output a tree of components that will be drawn to the screen. + +```tsx +class MyComponent { + render() { + return ( +
    +

    Hello World

    +

    This is JSX!

    +
    + ); + } +} +``` + +In this example we're returning the JSX representation of a `div`, with two child elements: an `h1` and a `p`. + +### Host Element + +If you want to modify the host element itself, such as adding a class or an attribute to the component itself, use the `` functional component. Check for more details [here](./host-element.md) + + +## Data Binding + +Components often need to render dynamic data. To do this in JSX, use `{ }` around a variable: + +```tsx +render() { + return ( +
    Hello {this.name}
    + ) +} +``` + +:::note +If you're familiar with ES6 template variables, JSX variables are very similar, just without the `$`: +::: + +```tsx +//ES6 +`Hello ${this.name}` + +//JSX +Hello {this.name} +``` + + +## Conditionals + +If we want to conditionally render different content, we can use JavaScript if/else statements: +Here, if `name` is not defined, we can just render a different element. + +```tsx +render() { + if (this.name) { + return (
    Hello {this.name}
    ) + } else { + return (
    Hello, World
    ) + } +} +``` + +Additionally, inline conditionals can be created using the JavaScript ternary operator: + +```tsx +render() { + return ( +
    + {this.name + ?

    Hello {this.name}

    + :

    Hello World

    + } +
    + ); +} +``` + +**Please note:** Stencil reuses DOM elements for better performance. Consider the following code: + +```tsx +{someCondition + ? + : +} +``` + +The above code behaves exactly the same as the following code: + +```tsx + +``` + +Thus, if `someCondition` changes, the internal state of `` won't be reset and its lifecycle methods such as `componentWillLoad()` won't fire. Instead, the conditional merely triggers an update to the very same component. + +If you want to destroy and recreate a component in a conditional, you can assign the `key` attribute. This tells Stencil that the components are actually different siblings: + +```tsx +{someCondition + ? + : +} +``` + +This way, if `someCondition` changes, you get a new `` component with fresh internal state that also runs the lifecycle methods `componentWillLoad()` and `componentDidLoad()`. + + +## Slots + +Components often need to render dynamic children in specific locations in their component tree, allowing a developer to supply child content when using our component, with our component placing that child component in the proper location. + +To do this, you can use the [Slot](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot) tag inside of your `my-component`. + +```tsx +// my-component.tsx + +render() { + return ( +
    +

    A Component

    +
    +
    + ); +} + +``` + +Then, if a user passes child components when creating our component `my-component`, then `my-component` will place that +component inside of the second `
    ` above: + +```tsx +render(){ + return( + +

    Child Element

    +
    + ) +} +``` + +Slots can also have `name`s to allow for specifying slot output location: + +```tsx +// my-component.tsx + +render(){ + return [ + , +

    Here is my main content

    , + + ] +} +``` + +```tsx +render(){ + return( + +

    I'll be placed before the h1

    +

    I'll be placed after the h1

    +
    + ) +} +``` + +### Slots Outside Shadow DOM + +:::caution +Slots are native to the [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), but Stencil polyfills +the behavior to work for non-shadow components as well. However, you may encounter issues using slots outside the Shadow DOM especially with +component trees mixing shadow and non-shadow components, or when passing a slot through many levels of components. In many cases, this behavior can +be remedied by wrapping the `slot` in an additional element (like a `div` or `span`) so the Stencil runtime can correctly "anchor" the relocated +content in its new location. +::: + +There are known use cases that the Stencil runtime is not able to support: + +- Forwarding slotted content to another slot with a different name:
    + It is recommended that slot names stay consistent when slotting content through multiple levels of components. **Avoid** defining slot tags like + ``. + +## Dealing with Children + +The children of a node in JSX correspond at runtime to an array of nodes, +whether they are created by mapping across an array with +[`Array.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) +or simply declared as siblings directly in JSX. This means that at runtime the +children of the two top-level divs below (`.todo-one` and `.todo-two`) will be +represented the same way: + + +```tsx +render() { + return ( + <> +
    + {this.todos.map((todo) => ( + { todo.taskName } + )} +
    +
    + { todos[0].taskName } + { todos[1].taskName } +
    + + ) +} +``` + +If this array of children is dynamic, i.e., if any nodes may be added, +removed, or reordered, then it's a good idea to set a unique `key` attribute on +each element like so: + +```tsx +render() { + return ( +
    + {this.todos.map((todo) => ( +
    +
    {todo.taskName}
    +
    + ))} +
    + ) +} +``` + +When nodes in a children array are rearranged Stencil makes an effort to +preserve DOM nodes across renders but it isn't able to do so in all cases. +Setting a `key` attribute lets Stencil ensure it can match up new and old +children across renders and thereby avoid recreating DOM nodes unnecessarily. + +:::caution +Do not use an array index or some other non-unique value as a key. Try to +ensure that each child has a key which does not change and which is unique +among all its siblings. +::: + +### Automatic Key Insertion + +During compilation Stencil will automatically add key attributes to any JSX +nodes in your component's render method which are not nested within curly +braces. This allows Stencil’s runtime to accurately reconcile children when +their order changes or when a child is conditionally rendered. + +For instance, consider a render method looking something like this: + +```tsx + render() { + return ( +
    + { this.disabled &&
    no key!
    } +
    + +
    +
    + ); + } +``` + +While it might seem like adding a key attribute to the `#slot-wrapper` div +could help ensure that elements will be matched up correctly when the component +re-renders, this is actually superfluous because Stencil will automatically add +a key to that element when it compiles your component. + +:::note +The Stencil compiler can only safely perform automatic key insertion in certain +scenarios where there is no danger of the keys accidentally causing elements to +be considered different when they should be treated the same (or vice versa). + +In particular, the compiler will not automatically insert `key` attributes if a +component's `render` method has more than one `return` statement or if it +returns a [conditional +expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator). +Additionally, the compiler will not add key attributes to any JSX which is +found within curly braces (`{ }`). +::: + +## Handling User Input + +Stencil uses native [DOM events](https://developer.mozilla.org/en-US/docs/Web/Events). + +Here's an example of handling a button click. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private handleClick = () => { + alert('Received the button click!'); + } + + render() { + return ( + + ); + } +} +``` + +Here's another example of listening to input `change`. Note the use of the [Arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). + +```tsx +... +export class MyComponent { + private inputChanged = (event: Event) => { + console.log('input changed: ', (event.target as HTMLInputElement).value); + } + + render() { + return ( + + ); + } +} +``` + + +## Complex Template Content + +So far we've seen examples of how to return only a single root element. We can also nest elements inside our root element + +In the case where a component has multiple "top level" elements, the `render` function can return an array. +Note the comma in between the `
    ` elements. + +```tsx +render() { + return ([ + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    , + + // second top level element, note the , above +
    + ... more html content ... +
    + ]); +} +``` + +Alternatively you can use the `Fragment` functional component, in which case you won't need to add commas: + +```tsx +import { Fragment } from '@stencil/core'; +... +render() { + return ( + // first top level element +
    +
      +
    • Item 1
    • +
    • Item 2
    • +
    • Item 3
    • +
    +
    + +
    + ... more html content ... +
    +
    ); +} +``` + +It is also possible to use `innerHTML` to inline content straight into an element. This can be helpful when, for example, loading an svg dynamically and then wanting to render that inside of a `div`. This works just like it does in normal HTML: + +```markup +
    +``` + +## Getting a reference to a DOM element + +In cases where you need to get a direct reference to an element, like you would normally do with `document.querySelector`, you might want to use a `ref` in JSX. Lets look at an example of using a `ref` in a form: + +```tsx +@Component({ + tag: 'app-home', +}) +export class AppHome { + + textInput!: HTMLInputElement; + + handleSubmit = (event: Event) => { + event.preventDefault(); + console.log(this.textInput.value); + } + + render() { + return ( +
    + + +
    + ); + } +} +``` + +In this example we are using `ref` to get a reference to our input `ref={(el) => this.textInput = el as HTMLInputElement}`. We can then use that ref to do things such as grab the value from the text input directly `this.textInput.value`. + + +## Avoid Shared JSX Nodes + +The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be shared within the same renderer. + +In the example below, the `sharedNode` variable is reused multiple times within the `render()` function. The renderer is able to optimize its DOM element lookups by caching the reference, however, this causes issues when nodes are reused. Instead, it's recommended to always generate unique nodes like the changed example below. + +```diff +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + render() { +- const sharedNode =
    Text
    ; + return ( +
    +- {sharedNode} +- {sharedNode} ++
    Text
    ++
    Text
    +
    + ); + } +} +``` + +Alternatively, creating a factory function to return a common JSX node could be used instead since the returned value would be a unique instance. For example: + +```tsx +@Component({ + tag: 'my-cmp', +}) +export class MyCmp { + + getText() { + return
    Text
    ; + } + + render() { + return ( +
    + {this.getText()} + {this.getText()} +
    + ); + } +} +``` + +## Other Resources + +- [Understanding JSX for StencilJS Applications](https://www.joshmorony.com/understanding-jsx-for-stencil-js-applications/) diff --git a/versioned_docs/version-v4.20/config/01-overview.md b/versioned_docs/version-v4.20/config/01-overview.md new file mode 100644 index 000000000..46e7caa33 --- /dev/null +++ b/versioned_docs/version-v4.20/config/01-overview.md @@ -0,0 +1,547 @@ +--- +title: Config +sidebar_label: Overview +description: Config +slug: /config +--- + +# Stencil Config + +In most cases, the `stencil.config.ts` file does not require any customization since Stencil comes with great default values out-of-the-box. In general, it's preferred to keep the config as minimal as possible. In fact, you could even delete the `stencil.config.ts` file entirely and an app would compile just fine. But at the same time, the compiler can be configured at the lowest levels using this config. Below are the many *optional* config properties. + +Example `stencil.config.ts`: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'MyApp', + srcDir: 'src' +}; +``` + +## buildDist + +*default: true (prod), false (dev)* + +Sets whether or not Stencil will execute output targets and write output to +`dist/` when `stencil build` is called. Defaults to `false` when building for +development and `true` when building for production. If set to `true` then +Stencil will always build all output targets, regardless of whether the build +is in dev or prod mode or using watch mode. + +```tsx +buildDist: true +``` + +## buildEs5 + +Sets if the ES5 build should be generated or not. +It defaults to `false`. +Setting `buildEs5` to `true` will also create ES5 builds for both dev and prod modes. +Setting `buildEs5` to `prod` will only build ES5 in prod mode. + +```tsx +buildEs5: boolean | 'prod' +``` + +## bundles + +By default, Stencil will statically analyze the application and generate a component graph of how all the components are interconnected. From the component graph it is able to best decide how components should be grouped depending on their usage with one another within the app. By doing so it's able to bundle components together in order to reduce network requests. However, bundles can be manually generated using the `bundles` config. + +The `bundles` config is an array of objects that represent how components are grouped together in lazy-loaded bundles. This config is rarely needed as Stencil handles this automatically behind the scenes. + +```tsx +bundles: [ + { components: ['ion-button'] }, + { components: ['ion-card', 'ion-card-header'] } +] +``` + +## cacheDir + +*default: '.stencil'* + +The directory where sub-directories will be created for caching when [`enableCache`](#enablecache) is set `true` or if using +[Stencil's Screenshot Connector](../testing/stencil-testrunner/07-screenshot-connector.md). + +A Stencil config like the following: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + enableCache: true, + cacheDir: '.cache', + testing: { + screenshotConnector: 'connector.js' + } +} +``` + +Will result in the following file structure: + +```tree +stencil-project-root +└── .cache + ├── .build <-- Where build related file caching is written + | + └── screenshot-cache.json <-- Where screenshot caching is written +``` + +## devServer + +Please see the [Dev-Server docs](./dev-server.md). + +## enableCache + +*default: `true`* + +Stencil will cache build results in order to speed up rebuilds. To disable this feature, set `enableCache` to `false`. + +```tsx +enableCache: true +``` + +## extras + +Please see the [Extras docs](./extras.md). + +## env + +*default: `{}`* + +An object that can hold environment variables for your components to import and use. These variables can hold data objects depending on the environment you compile the components for. For example, let's say we want to provide an URL to our API based on a specific environment, we could provide it as such: + +```ts title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + env: { + API_BASE_URL: process.env.API_BASE_URL + } +} +``` + +Now when you build your components with this environment variable set, you can import it in your component as follows: + +```ts +import { Component, h, Env, Host } from '@stencil/core'; + +@Component({ + tag: 'api-component', +}) +export class APIComponent { + async connectedCallback () { + const res = await fetch(Env.API_BASE_URL) + // ... + } +} +``` + +## generateExportMaps + +*default: `false`* + +Stencil will generate [export maps](https://nodejs.org/api/packages.html#packages_exports) that correspond with various output target outputs. This includes the root +entry point based on the [primary output target](../output-targets/01-overview.md#primary-package-output-target-validation) (or first eligible output target if not specified), +the entry point for the lazy-loader (if using the `dist` output target), and entry points for each component (if using `dist-custom-elements`). + +## globalScript + +The global script config option takes a file path as a string. + +The global script runs once before your library/app loads, so you can do things like setting up a connection to an external service or configuring a library you are using. + +The code to be executed should be placed within a default function that is exported by the global script. Ensure all of the code in the global script is wrapped in the function that is exported: + +```javascript +export default function() { // or export default async function() + initServerConnection(); +} +``` + +:::note +The exported function can also be `async` but be aware that this can have implications on the performance of your application as all rendering operations will be deferred until after the global script finishes. +::: + +## globalStyle + +Stencil is traditionally used to compile many components into an app, and each component comes with its own compartmentalized styles. However, it's still common to have styles which should be "global" across all components and the website. A global CSS file is often useful to set [CSS Variables](../components/styling.md). + +Additionally, the `globalStyle` config can be used to precompile styles with Sass, PostCSS, etc. + +Below is an example folder structure containing a webapp's global css file, named `app.css`. + +```bash +src/ + components/ + global/ + app.css +``` + +The global style config takes a file path as a string. The output from this build will go to the `buildDir`. In this example it would be saved to `www/build/app.css`. + +```tsx +globalStyle: 'src/global/app.css' +``` + +Check out the [styling docs](../components/styling.md#global-styles) of how to use global styles in your app. + +## hashedFileNameLength + +*default: `8`* + +When the `hashFileNames` config is set to `true`, and it is a production build, the `hashedFileNameLength` config is used to determine how many characters the file name's hash should be. + +```tsx +hashedFileNameLength: 8 +``` + +## hashFileNames + +*default: `true`* + +During production builds, the content of each generated file is hashed to represent the content, and the hashed value is used as the filename. If the content isn't updated between builds, then it receives the same filename. When the content is updated, then the filename is different. By doing this, deployed apps can "forever-cache" the build directory and take full advantage of content delivery networks (CDNs) and heavily caching files for faster apps. + +```tsx +hashFileNames: true +``` + +## hydratedFlag + +When using the [lazy build](https://stenciljs.com/docs/distribution) Stencil +has support for automatically applying a class or attribute to a component and +all of its child components when they have finished hydrating. This can be used +to prevent a [flash of unstyled content +(FOUC)](https://en.wikipedia.org/wiki/Flash_of_unstyled_content), a +typically-undesired 'flicker' of unstyled HTML that might otherwise occur +during component rendering while various components are asynchronously +downloaded and rendered. + +By default, Stencil will add the `hydrated` CSS class to elements to indicate +hydration. The `hydratedFlag` config field allows this behavior to be +customized, by changing the name of the applied CSS class, setting it to use an +attribute to indicate hydration, or changing which type of CSS properties and +values are assigned before and after hydrating. This config can also be used to +turn off this behavior by setting it to `null`. + +If a Stencil configuration does not supply a value for `hydratedFlag` then +Stencil will automatically generate the following default configuration: + +```ts +const defaultHydratedFlag: HydratedFlag = { + hydratedValue: 'inherit', + initialValue: 'hidden', + name: 'hydrated', + property: 'visibility', + selector: 'class', +}; +``` + +If `hydratedFlag` is explicitly set to `null`, Stencil will not set a default +configuration and the behavior of marking hydration with a class or attribute +will be disabled. + +```tsx +hydratedFlag: null | { + name?: string, + selector?: 'class' | 'attribute', + property?: string, + initialValue?: string, + hydratedValue?: string +} +``` + +The supported options are as follows: + +### name + +*default: 'hydrated'* + +The name which Stencil will use for the attribute or class that it sets on +elements to indicate that they are hydrated. + +```tsx +name: string +``` + +### selector + +*default: 'class'* + +The way that Stencil will indicate that a component has been hydrated. When +`'class'`, Stencil will set the `name` option on the element as a class, and +when `'attribute'`, Stencil will similarly set the `name` option as an +attribute. + +```tsx +selector: 'class' | 'attribute' +``` + +### property + +*default: 'visibility'* + +The CSS property used to show and hide components. This defaults to the CSS +`visibility` property. Other possible CSS properties might include `display` +with the `initialValue` setting as `none`, or `opacity` with the `initialValue` +as `0`. Defaults to `visibility`. + +```tsx +property: string +``` + +### initialValue + +*default: 'hidden'* + +This is the value which should be set for the property specified by `property` +on all components before hydration. + +```tsx +initialValue: string +``` + +### hydratedValue + +*default: 'inherit'* + +This is the value which should be set for the property specified by `property` +on all components once they've completed hydration. + +```tsx +hydratedValue: string +``` + +## invisiblePrehydration + +*default: `true`* + +When `true`, `invisiblePrehydration` will visually hide components before they are hydrated by adding an automatically injected style tag to the document's head. Setting `invisiblePrehydration` to `false` will not inject the style tag into the head, allowing you to style your web components pre-hydration. + +:::note +Setting `invisiblePrehydration` to `false` will cause everything to be visible when your page is loaded, causing a more prominent Flash of Unstyled Content (FOUC). However, you can style your web component's fallback content to your preference. +::: + +```tsx +invisiblePrehydration: true +``` + +## minifyCss + +_default: `true` in production_ + +When `true`, the browser CSS file will be minified. + +## minifyJs + +_default: `true` in production_ + +When `true`, the browser JS files will be minified. Stencil uses [Terser](https://terser.org/) under-the-hood for file minification. + +## namespace + +*default: `App`* + +The `namespace` config is a `string` representing a namespace for the app. For apps that are not meant to be a library of reusable components, the default of `App` is just fine. However, if the app is meant to be consumed as a third-party library, such as `Ionic`, a unique namespace is required. + +```tsx +namespace: "Ionic" +``` +## outputTargets + +Please see the [Output Target docs](../output-targets/01-overview.md). + +## plugins + +Please see the [Plugin docs](./plugins.md). + +## preamble + +*default: `undefined`* + +Used to help to persist a banner or add relevant information about the resulting build, the `preamble` configuration +field is a `string` that will be converted into a pinned comment and placed at the top of all emitted JavaScript files, +with the exception of any emitted polyfills. Escaped newlines may be placed in the provided value for this field and +will be honored by Stencil. + +Example: +```tsx +preamble: 'Built with Stencil\nCopyright (c) SomeCompanyInc.' +``` +Will generate the following comment: +```tsx +/*! + * Built with Stencil + * Copyright (c) SomeCompanyInc. + */ +``` + +## sourceMap + +*default: `true`* + +When omitted or set to `true`, sourcemaps will be generated for a project. +When set to `false`, sourcemaps will not be generated. + +```tsx +sourceMap: true | false +``` + +Sourcemaps create a translation between Stencil components that are written in TypeScript/JSX and the resulting +JavaScript that is output by Stencil. Enabling source maps in your project allows for an improved debugging experience +for Stencil components. For example, they allow external tools (such as an Integrated Development Environment) to add +breakpoints directly in the original source code, which allows you to 'step through' your code line-by-line, to inspect +the values held in variables, to observe logic flow, and more. + +Please note: Stencil will always attempt to minify a component's source code as much as possible during compilation. +When `sourceMap` is enabled, it is possible that a slightly different minified result will be produced by Stencil when +compared to the minified result produced when `sourceMap` is not enabled. + +Developers are responsible for determining whether or not they choose to serve sourcemaps in each environment their +components are served and implementing their decision accordingly. + +## srcDir + +*default: `src`* + +The `srcDir` config specifies the directory which should contain the source typescript files for each component. The standard for Stencil apps is to use `src`, which is the default. + +```tsx +srcDir: 'src' +``` + +## taskQueue + +*default: `async`* + +Sets the task queue used by stencil's runtime. The task queue schedules DOM read and writes +across the frames to efficiently render and reduce layout thrashing. By default, the +`async` is used. It's recommended to also try each setting to decide which works +best for your use-case. In all cases, if your app has many CPU intensive tasks causing the +main thread to periodically lock-up, it's always recommended to try +[Web Workers](../guides/workers.md) for those tasks. + +* `congestionAsync`: DOM reads and writes are scheduled in the next frame to prevent layout + thrashing. When the app is heavily tasked and the queue becomes congested it will then + split the work across multiple frames to prevent blocking the main thread. However, it can + also introduce unnecessary reflows in some cases, especially during startup. `congestionAsync` + is ideal for apps running animations while also simultaneously executing intensive tasks + which may lock-up the main thread. + +* `async`: DOM read and writes are scheduled in the next frame to prevent layout thrashing. + During intensive CPU tasks it will not reschedule rendering to happen in the next frame. + `async` is ideal for most apps, and if the app has many intensive tasks causing the main + thread to lock-up, it's recommended to try [Web Workers](../guides/workers.md) + rather than the congestion async queue. + +* `immediate`: Makes writeTask() and readTask() callbacks to be executed synchronously. Tasks + are not scheduled to run in the next frame, but do note there is at least one microtask. + The `immediate` setting is ideal for apps that do not provide long-running and smooth + animations. Like the async setting, if the app has intensive tasks causing the main thread + to lock-up, it's recommended to try [Web Workers](../guides/workers.md). + +```tsx +taskQueue: 'async' +``` + +## testing + +Please see the [testing config docs](../testing/stencil-testrunner/02-config.md). + +## transformAliasedImportPaths + +*default: `true`* + +This sets whether or not Stencil should transform [path aliases]( +https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) set +in a project's `tsconfig.json` from the assigned module aliases to resolved +relative paths. This will not transform external imports (like `@stencil/core`) or +relative imports (like `'../utils'`). + +This option applies globally and will affect all code processed by Stencil, +including `.d.ts` files and spec tests. + +An example of path transformation could look something like the following. + +First, a set of `paths` aliases in `tsconfig.json`: + +```json title="tsconfig.json" +{ + "compilerOptions": { + "paths": { + "@utils": [ + "../path/to/utils" + ] + } + } +} +``` + +Then with the following input: + +```ts title="src/my-module.ts" +import { utilFunc, UtilInterface } from '@utils' + +export function util(arg: UtilInterface) { + utilFunc(arg) +} +``` + +Stencil will produce the following output: + +```js title="dist/my-module.js" +import { utilFunc } from '../path/to/utils'; +export function util(arg) { + utilFunc(arg); +} +``` + +```ts title="dist/my-module.d.ts" +import { UtilInterface } from '../path/to/utils'; +export declare function util(arg: UtilInterface): void; +``` + +## validatePrimaryPackageOutputTarget + +*default: `false`* + +When `true`, validation for common `package.json` fields will occur based on setting an output target's `isPrimaryPackageOutputTarget` flag. +For more information on package validation, please see the [output target docs](../output-targets/01-overview.md#primary-package-output-target-validation). + +## rollupConfig + +Passes custom configuration down to rollup itself. The following options can be overwritten: + +- `inputOptions`: [`context`](https://rollupjs.org/configuration-options/#context), [`external`](https://rollupjs.org/configuration-options/#external), [`moduleContext`](https://rollupjs.org/configuration-options/#modulecontext) [`treeshake`](https://rollupjs.org/configuration-options/#treeshake) +- `outputOptions`: [`globals`](https://rollupjs.org/configuration-options/#output-globals) + +*default: `{}`* + +## watchIgnoredRegex + +*default: `[]`* + +*type: `RegExp | RegExp[]`* + +A regular expression (or array of regular expressions) that can be used to omit files from triggering a rebuild in watch mode. During compile-time, each file in the Stencil +project will be tested against each regular expression to determine if changes to the file (or directory) should trigger a project rebuild. + +:::note +If you want to ignore TS files such as `.ts`/`.js` or `.tsx`/`.jsx` extensions, these files will also need to be specified in your project's tsconfig's +[`watchOptions`](https://www.typescriptlang.org/docs/handbook/configuring-watch.html#configuring-file-watching-using-a-tsconfigjson) _in addition_ to the +`watchIgnoredRegex` option. For instance, if we wanted to ignore the `my-component.tsx` file, we'd specify: + +```json title="tsconfig.json" +{ + ..., + "watchOptions": { + "excludeFiles": ["src/components/my-component/my-component.tsx"] + } +} +``` + +::: diff --git a/versioned_docs/version-v4.20/config/_category_.json b/versioned_docs/version-v4.20/config/_category_.json new file mode 100644 index 000000000..b9de453d1 --- /dev/null +++ b/versioned_docs/version-v4.20/config/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Config", + "position": 5 +} diff --git a/versioned_docs/version-v4.20/config/cli.md b/versioned_docs/version-v4.20/config/cli.md new file mode 100644 index 000000000..5ea10a3a8 --- /dev/null +++ b/versioned_docs/version-v4.20/config/cli.md @@ -0,0 +1,107 @@ +--- +title: Stencil CLI +sidebar_label: CLI +description: Stencil CLI +slug: /cli +--- + +# Command Line Interface (CLI) + +Stencil's command line interface (CLI) is how developers can build their projects, run tests, and more. +Stencil's CLI is included in the compiler, and can be invoked with the `stencil` command in a project where `@stencil/core` is installed. + +## `stencil build` + +Builds a Stencil project. The flags below are the available options for the `build` command. + +| Flag | Description | Alias | +|------|-------------|-------| +| `--ci` | Run a build using recommended settings for a Continuous Integration (CI) environment. Defaults the number of workers to 4, allows for extra time if taking screenshots via the tests and modifies the console logs. | | +| `--config` | Path to the `stencil.config.ts` file. This flag is not needed in most cases since Stencil will find the config. Additionally, a Stencil config is not required. | `-c` | +| `--debug` | Adds additional runtime code to help debug, and sets the log level for more verbose output. | | +| `--dev` | Runs a development build. | | +| `--docs` | Generate all docs based on the component types, properties, methods, events, JSDocs, CSS Custom Properties, etc. | | +| `--es5` | Creates an ES5 compatible build. By default ES5 builds are not created during development in order to improve build times. However, ES5 builds are always created during production builds. Use this flag to create ES5 builds during development. | | +| `--log` | Write logs for the `stencil build` into `stencil-build.log`. The log file is written in the same location as the config. | | +| `--prerender` | Prerender the application using the `www` output target after the build has completed. | | +| `--prod` | Runs a production build which will optimize each file, improve bundling, remove unused code, minify, etc. A production build is the default, this flag is only used to override the `--dev` flag. | | +| `--max-workers` | Max number of workers the compiler should use. Defaults to use the same number of CPUs the Operating System has available. | | +| `--next` | Opt-in to test the "next" Stencil compiler features. | | +| `--no-cache` | Disables using the cache. | | +| `--no-open` | By default the `--serve` command will open a browser window. Using the `--no-open` command will not automatically open a browser window. | | +| `--port` | Port for the [Integrated Dev Server](./dev-server.md). Defaults to `3333`. | `-p` | +| `--serve` | Starts the [Integrated Dev Server](./dev-server.md). | | +| `--stats` | Write stats about the project to `stencil-stats.json`. The stats file is written in the same location as the config. | | +| `--verbose` | Logs additional information about each step of the build. | | +| `--watch` | Watches files during development and triggers a rebuild when files are updated. | | + +## `stencil docs` + +Performs a one-time generation of documentation for your project. +For more information on documentation generation, please see the [Documentation Generation section](../documentation-generation/01-overview.md). + +## `stencil generate` + +Alias: `stencil g` + +Starts the interactive generator for a new Stencil component. +The generator will ask you for a name for your component, and whether any stylesheets or testing files should be generated. + +If you wish to skip the interactive generator, a component tag name may be provided on the command line: +```shell +stencil generate my-new-component +``` + +All components will be generated within the `src/components` folder. +Within `src/components`, a directory will be created with the same name as the component tag name you provided containing the generated files. +For example, if you specify `page-home` as the component tag name, the files will be generated in `src/components/page-home`: +```plain +src +└── components + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +It is also possible to specify one or more sub-folders to generate the component in. +For example, if you specify `pages/page-home` as the component tag name, the files will be generated in `src/components/pages/page-home`: +```shell +stencil generate pages/page-home +``` +The command above will result in the following directory structure: +```plain +src +└── components + └── pages + └── page-home + ├── page-home.css + ├── page-home.e2e.ts + ├── page-home.spec.ts + └── page-home.tsx +``` + +## `stencil help` + +Aliases: `stencil --help`, `stencil -h` + +Prints various tasks that can be run and their associated flags to the terminal. + +## `stencil test` + +Tests a Stencil project. The flags below are the available options for the `test` command. + +| Flag | Description | +|------|-------------| +| `--spec` | Tests `.spec.ts` files using [Jest](https://jestjs.io/). | +| `--e2e` | Tests `.e2e.ts` files using [Puppeteer](https://developers.google.com/web/tools/puppeteer) and [Jest](https://jestjs.io/). | +| `--no-build` | Skips the build process before running end-to-end tests. When using this flag, it is assumed that your Stencil project has been built prior to running `stencil test`. Unit tests do not require this flag. | +| `--devtools` | Opens the dev tools panel in Chrome for end-to-end tests. Setting this flag will disable `--headless` | +| `--headless` | Sets the headless mode to use in Chrome for end-to-end tests. `--headless` and `--headless=true` will enable the "old" headless mode in Chrome, that was used by default prior to Chrome v112. `--headless=new` will enable the new headless mode introduced in Chrome v112. See [this article](https://developer.chrome.com/articles/new-headless/) for more information on Chrome's new headless mode. | + +## `stencil version` + +Aliases: `stencil -v`, `stencil --version` + +Prints the version of Stencil to the terminal. diff --git a/versioned_docs/version-v4.20/config/dev-server.md b/versioned_docs/version-v4.20/config/dev-server.md new file mode 100644 index 000000000..f83c55a05 --- /dev/null +++ b/versioned_docs/version-v4.20/config/dev-server.md @@ -0,0 +1,152 @@ +--- +title: Integrated Dev Server Config +sidebar_label: Dev Server +description: Integrated Dev Server Config +slug: /dev-server +--- + +# Integrated Dev Server + +Stencil comes with an integrated dev server in order to simplify development. By integrating the build process and the dev server, Stencil is able to drastically improve the development experience without requiring complicated build scripts and configuration. As app builds and re-builds take place, the compiler is able to communicate with the dev server, and vice versa. + +## Hot Module Replacement + +The compiler already provides a watch mode, but coupled with the dev server it's able to go one step farther by reloading only what has changed within the browser. Hot Module Replacement allows the app to keep its state within the browser, while switching out individual components with their updated logic after file saves. + +## Style Replacement + +Web components can come with their own css, can use shadow dom, and can have individual style tags. Traditionally, live-reload external css links usually does the trick, however, updating components with inline styles within shadow roots has been a challenge. With the integrated dev server, Stencil is able to dynamically update styles for all components, whether they're using shadow dom or not, without requiring a page refresh. + +## Development Errors + +When errors happen during development, such as printing an error for invalid syntax, Stencil will not only log the error and the source of the error in the console, but also overlay the app with the error so it's easier to read. + +## Open In Editor + +When a development error is shown and overlays the project within the browser, line numbers pointing to the source text are clickable, +which will open the source file directly in your IDE. + +## Dev Server Config + +### `address` + +**Optional** + +**Type: `string`** + +**Default: `0.0.0.0`** + +IP address used by the dev server. The default is `0.0.0.0`, which points to all IPv4 addresses on the local machine, such as `localhost`. + +### `basePath` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +Base path to be used by the server. Defaults to the root pathname. + +### `https` + +**Optional** + +**Type: `{ key: string; cert: string; } | false`** + +**Default: `false`** + +By default the dev server runs over the http protocol. Instead you can run it over https by providing your own SSL certificate and key (see example below). + +#### Example + +```tsx +import { readFileSync } from 'fs'; +import { Config } from '@stencil/core'; + +export const config: Config = { + devServer: { + reloadStrategy: 'pageReload', + port: 4444, + https: { + cert: readFileSync('cert.pem', 'utf8'), + key: readFileSync('key.pem', 'utf8'), + }, + }, +}; +``` + +### `initialLoadUrl` + +**Optional** + +**Type: `string`** + +**Default: `/`** + +The URL the dev server should first open to. + +### `logRequests` + +**Optional** + +**Type: `boolean`** + +**Default: `false`** + +Every request to the server will be logged within the terminal. + +### `openBrowser` + +**Optional** + +**Type: `boolean`** + +**Default: `true`** + +By default, when dev server is started the local dev URL is opened in your default browser. However, to prevent this URL to be opened change this value to `false`. + +### `pingRoute` + +**Optional** + +**Type: `string | null`** + +**Default: `/ping`** + +Route to be registered on the dev server that will respond with a 200 OK response once the Stencil build has completed. The Stencil dev server will "spin up" +before the build process has completed, which can cause issues with processes that rely on the compiled and served output (like E2E testing). This route provides +a way for these processes to know when the build has finished and is ready to be accessed. + +If set to `null`, no route will be registered. + +### `port` + +**Optional** + +**Type: `number`** + +**Default: `3333`** + +Sets the server's port. + +### `reloadStrategy` + +**Optional** + +**Type: `'hmr' | 'pageReload' | null`** + +**Default: `hmr`** + +When files are watched and updated, by default the dev server will use `hmr` (Hot Module Replacement) to update the page without a full page refresh. +To have the page do a full refresh use `pageReload`. To disable any reloading, use `null`. + +### `root` + +**Optional** + +**Type: `string`** + +**Default: `www` output directory if exists, project root otherwise** + +The directory to serve files from. diff --git a/versioned_docs/version-v4.20/config/extras.md b/versioned_docs/version-v4.20/config/extras.md new file mode 100644 index 000000000..bfed8bfac --- /dev/null +++ b/versioned_docs/version-v4.20/config/extras.md @@ -0,0 +1,141 @@ +--- +title: Extras Config +sidebar_label: Extras +description: Extras Config +slug: /config-extras +--- + +# Extras + +The `extras` config contains options to enable new/experimental features in +Stencil, add & remove runtime for DOM features that require manipulations to +polyfills, etc. For example, not all DOM APIs are fully polyfilled when using +the Slot polyfill. Most of these are opt-in, since not all users require the +additional runtime. + +### appendChildSlotFix + +By default, the slot polyfill does not update `appendChild()` so that it appends new child nodes into the correct child slot like how shadow dom works. This is an opt-in polyfill for those who need it. + +### cloneNodeFix + +By default, the runtime does not polyfill `cloneNode()` when cloning a component that uses the slot polyfill. This is an opt-in polyfill for those who need it. + +### enableImportInjection + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +Enabling this flag will allow downstream projects that consume a Stencil library and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalImportInjection + +:::caution +This flag has been deprecated in favor of [`enableImportInjection`](#enableimportinjection), which provides the same +functionality. `experimentalImportInjection` will be removed in a future major version of Stencil. +::: + +In some cases, it can be difficult to lazily load Stencil components in a separate project that uses a bundler such as +[Vite](https://vitejs.dev/). + +This is an experimental flag that, when set to `true`, will allow downstream projects that consume a Stencil library +and use a bundler such as Vite to lazily load the Stencil library's components. + +In order for this flag to work: + +1. The Stencil library must expose lazy loadable components, such as those created with the + [`dist` output target](../output-targets/dist.md) +2. The Stencil library must be recompiled with this flag set to `true` + +This flag works by creating dynamic import statements for every lazily loadable component in a Stencil project. +Users of this flag should note that they may see an increase in their bundle size. + +Defaults to `false`. + +### experimentalScopedSlotChanges + +This option updates runtime behavior for Stencil's support of slots in **scoped** components to match more closely with +the native Shadow DOM behaviors. + +When set to `true`, the following behaviors will be applied: + +- Stencil will hide projected nodes that do not have a destination `slot` ([#2778](https://github.com/ionic-team/stencil/issues/2877)) (since v4.10.0) +- The `textContent` getter will return the text content of all nodes located in a slot (since v4.10.0) +- The `textContent` setter will overwrite all nodes located in a slot (since v4.10.0) + +Defaults to `false`. + +:::note +These behaviors only apply to components using scoped encapsulation! +::: + +### experimentalSlotFixes + +This option enables all current and future slot-related fixes. When enabled it +will enable the following options, overriding their values if they are +specified separately: + +- [`slotChildNodesFix`](#slotchildnodesfix) +- [`scopedSlotTextContentFix`](#scopedslottextcontentfix). +- [`appendChildSlotFix`](#appendchildslotfix) +- [`cloneNodeFix`](#clonenodefix) + +Slot-related fixes to the runtime will be added over the course of Stencil v4, +with the intent of making these the default behavior in Stencil v5. When set to +`true` fixes for the following issues will be applied: + +- Elements rendered outside of slot when shadow not enabled [(#2641)](https://github.com/ionic-team/stencil/issues/2641) (since v4.2.0) +- A slot gets the attribute hidden when it shouldn't [(#4523)](https://github.com/ionic-team/stencil/issues/4523) (since v4.7.0) +- Nested slots mis-ordered when not using Shadow DOM [(#2997)](https://github.com/ionic-team/stencil/issues/2997) (since v4.7.0) +- Inconsistent behavior: slot-fb breaks styling of default slot content in component with 'shadow: false' [(#2937)](https://github.com/ionic-team/stencil/issues/2937) (since v4.7.2) +- Slot content went missing within dynamic component [(#4284)](https://github.com/ionic-team/stencil/issues/4284) (since v4.8.2) +- Slot element loses its parent reference and disappears when its parent is rendered conditionally [(#3913)](https://github.com/ionic-team/stencil/issues/3913) (since v4.8.2) +- Failed to execute 'removeChild' on 'Node' [(#3278)](https://github.com/ionic-team/stencil/issues/3278) (since v4.9.0) +- React fails to manage children in Stencil slot [(#2259)](https://github.com/ionic-team/stencil/issues/2259) (since v4.9.0) +- Slot name is not updated when it is bind to a prop [(#2982)](https://github.com/ionic-team/stencil/issues/2982) (since 4.12.1) +- Conditionally rendered slots not working [(#5335)](https://github.com/ionic-team/stencil/issues/5335) (since 4.13.0) + +:::note +New fixes enabled by this experimental flag are not subject to Stencil's +[semantic versioning policy](../reference/versioning.md). +::: + +### lifecycleDOMEvents + +Dispatches component lifecycle events. By default these events are not dispatched, but by enabling this to `true` these events can be listened for on `window`. Mainly used for testing. + +| Event Name | Description | +| ----------------------------- | ------------------------------------------------------ | +| `stencil_componentWillLoad` | Dispatched for each component's `componentWillLoad`. | +| `stencil_componentWillUpdate` | Dispatched for each component's `componentWillUpdate`. | +| `stencil_componentWillRender` | Dispatched for each component's `componentWillRender`. | +| `stencil_componentDidLoad` | Dispatched for each component's `componentDidLoad`. | +| `stencil_componentDidUpdate` | Dispatched for each component's `componentDidUpdate`. | +| `stencil_componentDidRender` | Dispatched for each component's `componentDidRender`. | + +### scopedSlotTextContentFix + +An experimental flag that when set to `true`, aligns the behavior of invoking the `textContent` getter/setter on a scoped component to act more like a component that uses the shadow DOM. Specifically, invoking `textContent` on a component will adhere to the return values described in [MDN's article on textContent](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#description). Defaults to `false`. + +### scriptDataOpts + +:::caution +This option has been deprecated and will be removed in the next major Stencil release. +::: + +It is possible to assign data to the actual ` + + + + + +``` + +Alternatively, if you wanted to take advantage of ES Modules, you could include the components using an import statement. + +```markup + + + + + + + + +``` + +## Passing object props from a non-JSX element + +### Setting the prop manually + +```tsx +import { Prop } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: object; + @Prop() myArray: Array; +} +``` + +```markup + + +``` + +### Watching props changes + +```tsx +import { Prop, State, Watch } from '@stencil/core'; + +export class TodoList { + @Prop() myObject: string; + @Prop() myArray: string; + @State() myInnerObject: object; + @State() myInnerArray: Array; + + componentWillLoad() { + this.parseMyObjectProp(this.myObject); + this.parseMyArrayProp(this.myArray); + } + + @Watch('myObject') + parseMyObjectProp(newValue: string) { + if (newValue) this.myInnerObject = JSON.parse(newValue); + } + + @Watch('myArray') + parseMyArrayProp(newValue: string) { + if (newValue) this.myInnerArray = JSON.parse(newValue); + } +} +``` + +```tsx + +``` diff --git a/versioned_docs/version-v4.20/framework-integration/react.md b/versioned_docs/version-v4.20/framework-integration/react.md new file mode 100644 index 000000000..973272942 --- /dev/null +++ b/versioned_docs/version-v4.20/framework-integration/react.md @@ -0,0 +1,505 @@ +--- +title: React Integration with Stencil +sidebar_label: React +description: Learn how to wrap your components so that people can use them natively in React +slug: /react +--- + +# React Integration + +**Supports: React v16.7+ • TypeScript 3.7+ • Stencil v2.9.0+** + +Stencil can generate React component wrappers for your web components. This allows your Stencil components to be used within +a React application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Custom events will be handled correctly and correctly propagate through the React render tree +- Properties and attributes that are not a string or number will be correctly bound to the component + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component +wrappers. Your project workspace should contain your Stencil component library and the library for the generated React component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── stencil-library/ + │ ├── stencil.config.js + │ └── src/components/ + └── react-library/ + └── src/ + ├── components/ + └── index.ts +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +From the `packages/` directory, run the following commands to create a Stencil component library: + +```bash npm2yarn +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a React Component Library + +:::note +If you already have a React component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a React library package to write to. + +Run the following commands from the root directory of your monorepo to create a React component library: + +```bash npm2yarn +# Create a project +lerna create react-library # fill out the prompts accordingly +cd packages/react-library + +# Install core dependencies +npm install react react-dom typescript @types/react --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `react-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2015"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2015", + "skipLibCheck": true, + "jsx": "react", + "allowSyntheticDefaultImports": true, + "declarationDir": "./dist/types" + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `react-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/react-library.js", ++ "main": "dist/index.js", ++ "module": "dist/index.js", ++ "types": "dist/types/index.d.ts", + "scripts": { +- "test": "node ./__tests__/react-library.test.js" ++ "test": "node ./__tests__/react-library.test.js", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, + "files": [ +- "lib" ++ "dist" + ], ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the React Output Target + +Install the `@stencil/react-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency +npm install @stencil/react-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `reactOutputTarget` configuration to the `outputTargets` array: + +```ts +import { reactOutputTarget } from '@stencil/react-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // React target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + reactOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../react-library/lib/components/stencil-generated/index.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all of the React component wrappers. You will replace the +file path to match your project's structure and respective names. You can generate any file name instead of `index.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +See the [API section below](#api) for details on each of the output target's options. + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers +npm run build +``` + +If the build is successful, you’ll see the new generated file in your React component library at the location specified by the `proxiesFile` argument. + +### Add the Components to your React Component Library's Entry File + +In order to make the generated files available within your React component library and its consumers, you’ll need to export everything from within your entry file. First, rename `react-library.js` to `index.ts`. Then, modify the contents to match the following: + +```tsx +export * from './components/stencil-generated'; +``` + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you'll need to expose a method for registering the underlying Stencil +generated custom elements for the React proxy components to leverage. The easiest way to do this is to modify the React library's entry file +to re-export the Stencil loader's `defineCustomElements()` method. In your React library's entry file (`packages/react-library/lib/index.ts`), +add the following: + +```diff +export * from "./components/stencil-generated"; ++ export { defineCustomElements } from "stencil-library/loader"; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your React component library, you will need to link the Stencil package to the React package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your React component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the React component library. + +:::tip +As an alternative to `npm link` , you can also run `npm install` with a relative path to your Stencil component library. This strategy, however, will +modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer React App + +:::note +If you already have a React app, skip this section. +::: + +From the `packages/` directory, run the following commands to create a starter React app: + + + + +```bash +# Create the React app +npm create vite@latest my-app -- --template react-ts +# of if using yarn +yarn create vite my-app --template react-ts + +cd ./my-app + +# install dependencies +npm install +# or if using yarn +yarn install +``` + +You'll also need to link your React component library as a dependency. This step makes it so your React app will be able to correctly resolve imports from your React library. This +is easily done by modifying your React app's `package.json` to include the following: + +```json +"dependencies": { + "react-library": "*" +} +``` + +### Consuming the React Wrapper Components + +This section covers how developers consuming your React component wrappers will use your package and component wrappers. + +Before you can consume your React proxy components, you'll need to build your React component library. From `packages/react-library` run: + +```bash npm2yarn +npm run build +``` + +To make use of your React component library in your React application, import your components from your React component library in the file where you want to use them. + +```tsx +// App.tsx +import './App.css'; +import { MyComponent, defineCustomElements } from 'react-library'; + +defineCustomElements(); + +function App() { + return ( +
    + +
    + ); +} + +export default App; +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + reactOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate React wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with React Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements](../output-targets/custom-elements.md) output and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your React project. + +## FAQ's + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + reactOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the React output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the React application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the React component library. + +### What is the best format to write event names? + +Event names shouldn’t include special characters when initially written in Stencil. Try to lean on using camelCased event names for interoperability between frameworks. diff --git a/versioned_docs/version-v4.20/framework-integration/vue.md b/versioned_docs/version-v4.20/framework-integration/vue.md new file mode 100644 index 000000000..143a858a8 --- /dev/null +++ b/versioned_docs/version-v4.20/framework-integration/vue.md @@ -0,0 +1,673 @@ +--- +title: VueJS Integration with Stencil +sidebar_label: Vue +description: Learn how to wrap your components so that people can use them natively in Vue +slug: /vue +--- + +# Vue Integration + +**Supports: Vue 3 • TypeScript 4.0+ • Stencil v2.9.0+** + +Stencil can generate Vue component wrappers for your web components. This allows your Stencil components to be used within a Vue 3 application. The benefits of using Stencil's component wrappers over the standard web components include: + +- Type checking with your components. +- Integration with the router link and Vue router. +- Optionally, form control web components can be used with `v-model`. + +## Setup + +### Project Structure + +We recommend using a [monorepo](https://www.toptal.com/front-end/guide-to-monorepos) structure for your component library with component wrappers. Your project workspace should contain your Stencil component library and the library for the generate Vue component wrappers. + +An example project set-up may look similar to: + +``` +top-most-directory/ +└── packages/ + ├── vue-library/ + │ └── lib/ + │ ├── plugin.ts + │ └── index.ts + └── stencil-library/ + ├── stencil.config.js + └── src/components +``` + +This guide uses Lerna for the monorepo, but you can use other solutions such as Nx, Turborepo, etc. + +To use Lerna with this walk through, globally install Lerna: + +```bash npm2yarn +npm install --global lerna +``` + +#### Creating a Monorepo + +:::note +If you already have a monorepo, skip this section. +::: + +```bash npm2yarn +# From your top-most-directory/, initialize a workspace +lerna init + +# install dependencies +npm install + +# install typescript and node types +npm install typescript @types/node --save-dev +``` + +#### Creating a Stencil Component Library + +:::note +If you already have a Stencil component library, skip this section. +::: + +```bash npm2yarn +cd packages/ +npm init stencil components stencil-library +cd stencil-library +# Install dependencies +npm install +``` + +#### Creating a Vue Component Library + +:::note +If you already have a Vue component library, skip this section. +::: + +The first time you want to create the component wrappers, you will need to have a Vue library package to write to. + +Using Lerna and Vue's CLI, generate a workspace and a library for your Vue component wrappers: + +```bash npm2yarn +# From your top-most-directory/ +lerna create vue-library +# Follow the prompts and confirm +cd packages/vue-library +# Install Vue dependency +npm install vue@3 --save-dev +``` + +Lerna does not ship with a TypeScript configuration. At the root of the workspace, create a `tsconfig.json`: + +```json +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "noImplicitAny": false, + "removeComments": true, + "noLib": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "target": "es6", + "sourceMap": true, + "lib": ["es6"] + }, + "exclude": ["node_modules", "**/*.spec.ts", "**/__tests__/**"] +} +``` + +In your `vue-library` project, create a project specific `tsconfig.json` that will extend the root config: + +```json +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "lib": ["dom", "es2020"], + "module": "es2015", + "moduleResolution": "node", + "target": "es2017", + "skipLibCheck": true + }, + "include": ["lib"], + "exclude": ["node_modules"] +} +``` + +Update the generated `package.json` in your `vue-library`, adding the following options to the existing config: + +```diff +{ +- "main": "lib/vue-library.js", ++ "main": "dist/index.js", ++ "types": "dist/index.d.ts", + "files": [ +- 'lib' ++ 'dist' + ], + "scripts": { +- "test": "echo \"Error: run tests from root\" && exit 1" ++ "test": "echo \"Error: run tests from root\" && exit 1", ++ "build": "npm run tsc", ++ "tsc": "tsc -p . --outDir ./dist" +- } ++ }, ++ "publishConfig": { ++ "access": "public" ++ }, ++ "dependencies": { ++ "stencil-library": "*" ++ } +} +``` + +:::note +The `stencil-library` dependency is how Lerna knows to resolve the internal Stencil library dependency. See Lerna's documentation on +[package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management) for more information. +::: + +### Adding the Vue Output Target + +Install the `@stencil/vue-output-target` dependency to your Stencil component library package. + +```bash npm2yarn +# Install dependency (from `packages/stencil-library`) +npm install @stencil/vue-output-target --save-dev +``` + +In your project's `stencil.config.ts`, add the `vueOutputTarget` configuration to the `outputTargets` array: + +```ts +import { vueOutputTarget } from '@stencil/vue-output-target'; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + // By default, the generated proxy components will + // leverage the output from the `dist` target, so we + // need to explicitly define that output alongside the + // Vue target + { + type: 'dist', + esmLoaderPath: '../loader', + }, + vueOutputTarget({ + componentCorePackage: 'stencil-library', + proxiesFile: '../vue-library/lib/components.ts', + }), + ], +}; +``` + +:::tip +The `proxiesFile` is the relative path to the file that will be generated with all the Vue component wrappers. You will replace the file path to match +your project's structure and respective names. You can generate any file name instead of `components.ts`. + +The `componentCorePackage` should match the `name` field in your Stencil project's `package.json`. +::: + +You can now build your Stencil component library to generate the component wrappers. + +```bash npm2yarn +# Build the library and wrappers (from `packages/stencil-library`) +npm run build +``` + +If the build is successful, you will now have contents in the file specified in `proxiesFile`. + +### Registering Custom Elements + +To register your web components for the lazy-loaded (hydrated) bundle, you will need to create a new file for the Vue plugin: + +```ts +// packages/vue-library/lib/plugin.ts + +import { Plugin } from 'vue'; +import { applyPolyfills, defineCustomElements } from 'stencil-library/loader'; + +export const ComponentLibrary: Plugin = { + async install() { + applyPolyfills().then(() => { + defineCustomElements(); + }); + }, +}; +``` + +You can now finally export the generated component wrappers and the Vue plugin for your component library to make them available to implementers. Export +the `plugin.ts` file created in the previous step, as well as the file `proxiesFile` generated by the Vue Output Target: + +```ts +// packages/vue-library/lib/index.ts +export * from './components'; +export * from './plugin'; +``` + +### Link Your Packages (Optional) + +:::note +If you are using a monorepo tool (Lerna, Nx, etc.), skip this section. +::: + +Before you can successfully build a local version of your Vue component library, you will need to link the Stencil package to the Vue package. + +From your Stencil project's directory, run the following command: + +```bash npm2yarn +# Link the working directory +npm link +``` + +From your Vue component library's directory, run the following command: + +```bash npm2yarn +# Link the package name +npm link name-of-your-stencil-package +``` + +The name of your Stencil package should match the `name` property from the Stencil component library's `package.json`. + +Your component libraries are now linked together. You can make changes in the Stencil component library and run `npm run build` to propagate the +changes to the Vue component library. + +:::note +As an alternative to `npm link`, you can also run `npm install` with a relative path to your Stencil component library. This strategy, +however, will modify your `package.json` so it is important to make sure you do not commit those changes. +::: + +## Consumer Usage + +### Creating a Consumer Vue App + +From the `packages/` directory, run the following command to generate a Vue app: + +```bash npm2yarn +npm init vue@3 my-app +``` + +Follow the prompts and choose the options best for your project. + +You'll also need to link your Vue component library as a dependency. This step makes it so your Vue app will be able to correctly +resolve imports from your Vue library. This is easily done by modifying your Vue app's `package.json` to include the following: + +```json +"dependencies": { + "vue-library": "*" +} +``` + +For more information, see the Lerna documentation on [package dependency management](https://lerna.js.org/docs/getting-started#package-dependency-management). + +Lastly, you'll want to update the generated `vite.config.ts`: + +```diff +export default defineConfig({ +- plugins: [vue(), vueJsx()], ++ plugins: [ ++ vue({ ++ template: { ++ compilerOptions: { ++ // treat all tags with a dash as custom elements ++ isCustomElement: (tag) => tag.includes('-'), ++ }, ++ }, ++ }), ++ vueJsx(), ++ ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + } +}) +``` + +This will prevent Vue from logging a warning about failing to resolve components (e.g. "Failed to resolve component: my-component"). + +### Consuming the Vue Wrapper Components + +This section covers how developers consuming your Vue component wrappers will use your package and component wrappers. + +Before you can use your Vue proxy components, you'll need to build your Vue component library. From `packages/vue-library` simply run: + +```bash npm2yarn +npm run build +``` + +In your `main.js` file, import your component library plugin and use it: + +```js +// src/main.js +import { ComponentLibrary } from 'vue-library'; + +createApp(App).use(ComponentLibrary).mount('#app'); +``` + +In your page or component, you can now import and use your component wrappers: + +```html + +``` + +## API + +### componentCorePackage + +**Optional** + +**Default: The `components.d.ts` file in the Stencil project's `package.json` types field** + +**Type: `string`** + +The name of the Stencil package where components are available for consumers (i.e. the value of the `name` property in your Stencil component library's `package.json`). +This is used during compilation to write the correct imports for components. + +For a starter Stencil project generated by running: + +```bash npm2yarn +npm init stencil component my-component-lib +``` + +The `componentCorePackage` would be set to: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'my-component-lib', + // ... additional config options + }) + ] +} +``` + +Which would result in an import path like: + +```js +import { defineCustomElement as defineMyComponent } from 'my-component-lib/components/my-component.js'; +``` + +:::note +Although this field is optional, it is _highly_ recommended that it always be defined to avoid potential issues with paths not being generated correctly +when combining other API arguments. +::: + +### componentModels + +**Optional** + +**Default: `[]`** + +**Type: `ComponentModelConfig[]`** + +This option is used to define which components should be integrated with `v-model`. It allows you to set what the target prop is (i.e. `value`), +which event will cause the target prop to change, and more. + +```tsx +const componentModels: ComponentModelConfig[] = [ + { + elements: ['my-input', 'my-textarea'], + event: 'v-on-change', + externalEvent: 'on-change', + targetAttr: 'value', + }, +]; + +export const config: Config = { + namespace: 'stencil-library', + outputTargets: [ + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + componentModels: componentModels, + }), + ], +}; +``` + +### customElementsDir + +**Optional** + +**Default: 'dist/components'** + +**Type: `string`** + +If [includeImportCustomElements](#includeimportcustomelements) is `true`, this option can be used to specify the directory where the generated +custom elements live. This value only needs to be set if the `dir` field on the `dist-custom-elements` output target was set to something other than +the default directory. + +### excludeComponents + +**Optional** + +**Default: `[]`** + +**Type: `string[]`** + +This lets you specify component tag names for which you don't want to generate Vue wrapper components. This is useful if you need to write framework-specific versions of components. For instance, in Ionic Framework, this is used for routing components - like tabs - so that +Ionic Framework can integrate better with Vue's Router. + +### includeDefineCustomElements + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, all Web Components will automatically be registered with the Custom Elements Registry. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is `true`. + +### includeImportCustomElements + +**Optional** + +**Default: `undefined`** + +**Type: `boolean`** + +If `true`, the output target will import the custom element instance and register it with the Custom Elements Registry when the component is imported inside of a user's app. This can only be used with the [Custom Elements Bundle](../output-targets/custom-elements.md) and will not work with lazy loaded components. + +:::note +The configuration for the [Custom Elements](../output-targets/custom-elements.md) output target must set the +[export behavior](../output-targets/custom-elements.md#customelementsexportbehavior) to `single-export-module` for the wrappers to generate correctly. +::: + +### includePolyfills + +**Optional** + +**Default: `true`** + +**Type: `boolean`** + +If `true`, polyfills will automatically be imported and the `applyPolyfills` function will be called in your proxies file. This can only be used when lazy loading Web Components and will not work when `includeImportCustomElements` is enabled. + +### loaderDir + +**Optional** + +**Default: `/dist/loader`** + +**Type: `string`** + +The path to where the `defineCustomElements` helper method exists within the built project. This option is only used when `includeDefineCustomElements` is enabled. + +### proxiesFile + +**Required** + +**Type: `string`** + +This parameter allows you to name the file that contains all the component wrapper definitions produced during the compilation process. This is the first file you should import in your Vue project. + +## FAQ + +### Do I have to use the `dist` output target? + +No! By default, this output target will look to use the `dist` output, but the output from `dist-custom-elements` can be used alternatively. + +To do so, simply set the `includeImportCustomElements` option in the output target's config and ensure the +[custom elements output target](../output-targets/custom-elements.md) is added to the Stencil config's output target array: + +```ts +// stencil.config.ts + +export const config: Config = { + ..., + outputTargets: [ + // Needs to be included + { + type: 'dist-custom-elements' + }, + vueOutputTarget({ + componentCorePackage: 'component-library', + proxiesFile: '{path to your proxy file}', + // This is what tells the target to use the custom elements output + includeImportCustomElements: true + }) + ] +} +``` + +Now, all generated imports will point to the default directory for the custom elements output. If you specified a different directory +using the `dir` property for `dist-custom-elements`, you need to also specify that directory for the Vue output target. See +[the API section](#customelementsdir) for more information. + +In addition, all the Web Components will be automatically defined as the generated component modules are bootstrapped. + +### TypeError: Cannot read properties of undefined (reading 'isProxied') + +If you encounter this error when running the Vue application consuming your proxy components, you can set the [`enableImportInjection`](../config/extras.md#enableimportinjection) +flag on the Stencil config's `extras` object. Once set, this will require you to rebuild the Stencil component library and the Vue component library. + +### Vue warns "Failed to resolve component: my-component" + +#### Lazy loaded bundle + +If you are using Vue CLI, update your `vue.config.js` to match your custom element selector as a custom element: + +```js +const { defineConfig } = require('@vue/cli-service'); +module.exports = defineConfig({ + transpileDependencies: true, + chainWebpack: (config) => { + config.module + .rule('vue') + .use('vue-loader') + .tap((options) => { + options.compilerOptions = { + ...options.compilerOptions, + // The stencil-library components start with "my-" + isCustomElement: (tag) => tag.startsWith('my-'), + }; + return options; + }); + }, +}); +``` + +#### Custom elements bundle + +If you see this warning, then it is likely you did not import your component from your Vue library: `vue-library`. By default, all Vue components are locally registered, meaning you need to import them each time you want to use them. + +Without importing the component, you will only get the underlying Web Component, and Vue-specific features such as `v-model` will not work. + +To resolve this issue, you need to import the component from `vue-library` (your package name) and provide it to your Vue component: + +```html + + + +``` + +### Vue warns: "slot attributes are deprecated vue/no-deprecated-slot-attribute" + +The slots that are used in Stencil are [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots) slots, which are different than the slots used in Vue 2. Unfortunately, the APIs for both are very similar, and your linter is likely getting the two confused. + +You will need to update your lint rules in `.eslintrc.js` to ignore this warning: + +```js +module.exports = { + rules: { + 'vue/no-deprecated-slot-attribute': 'off', + }, +}; +``` + +If you are using VSCode and have the Vetur plugin installed, you are likely getting this warning because of Vetur, not ESLint. By default, Vetur loads the default Vue 3 linting rules and ignores any custom ESLint rules. + +To resolve this issue, you will need to turn off Vetur's template validation with `vetur.validation.template: false`. See the [Vetur Linting Guide](https://vuejs.github.io/vetur/guide/linting-error.html#linting) for more information. + +### Method on component is not a function + +In order to access a method on a Stencil component in Vue, you will need to access the underlying Web Component instance first: + +```ts +// ✅ This is correct +myComponentRef.value.$el.someMethod(); + +// ❌ This is incorrect and will result in an error. +myComponentRef.value.someMethod(); +``` + +### Output commonjs bundle for Node environments + +First, install `rollup` and `rimraf` as dev dependencies: + +```bash npm2yarn +npm i -D rollup rimraf +``` + +Next, create a `rollup.config.js` in `/packages/vue-library/`: + +```js +const external = ['vue', 'vue-router']; + +export default { + input: 'dist-transpiled/index.js', + output: [ + { + dir: 'dist/', + entryFileNames: '[name].esm.js', + chunkFileNames: '[name]-[hash].esm.js', + format: 'es', + sourcemap: true, + }, + { + dir: 'dist/', + format: 'commonjs', + preferConst: true, + sourcemap: true, + }, + ], + external: (id) => external.includes(id) || id.startsWith('stencil-library'), +}; +``` + +:::info +Update the `external` list for any external dependencies. Update the `stencil-library` to match your Stencil library's package name. +::: + +Next, update your `package.json` to include the scripts for rollup: + +```json +{ + "scripts": { + "build": "npm run clean && npm run tsc && npm run bundle", + "bundle": "rollup --config rollup.config.js", + "clean": "rimraf dist dist-transpiled" + } +} +``` diff --git a/versioned_docs/version-v4.20/guides/_category_.json b/versioned_docs/version-v4.20/guides/_category_.json new file mode 100644 index 000000000..afdb49ff4 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Guides", + "position": 8 +} diff --git a/versioned_docs/version-v4.20/guides/assets.md b/versioned_docs/version-v4.20/guides/assets.md new file mode 100644 index 000000000..f6dda9fce --- /dev/null +++ b/versioned_docs/version-v4.20/guides/assets.md @@ -0,0 +1,284 @@ +--- +title: Assets +sidebar_label: Assets +description: Learn how to reference assets in your components +slug: /assets +--- + +# Assets + +Stencil components may need one or more static files as a part of their design. +These types of files are referred to as 'assets', and include images, fonts, etc. + +In this guide, we describe different strategies for resolving assets on the filesystem. + +:::note +CSS files are handled differently than assets; for more on using CSS, please see the [styling documentation](../components/styling.md). +::: + +## Asset Base Path + +The **asset base path** is the directory that Stencil will use to resolve assets. +When a component uses an asset, the asset's location is resolved relative to the asset base path. + +The asset base path is automatically set for the following output targets: +- [dist](../output-targets/dist.md) +- [hydrate](./hydrate-app.md) +- [www](../output-targets/www.md) + +For all other output targets, assets must be [moved](#manually-moving-assets) and the asset base path must be [manually set](#setassetpath). + +For each instance of the Stencil runtime that is loaded, there is a single asset base path. +Oftentimes, this means there is only one asset base path per application using Stencil. + +## Resolution Overview + +The process of resolving an asset involves asking Stencil to build a path to the asset on the filesystem. + +When an asset's path is built, the resolution is always done in a project's compiled output, not the directory containing the original source code. + +The example below uses the output of the [`www` output target](../output-targets/www.md) to demonstrate how assets are resolved. +Although the example uses the output of `www` builds, the general principle of how an asset is found holds for all output targets. + +When using the `www` output target, a `build/` directory is automatically created and set as the asset base path. +An example `build/` directory and the assets it contains can be found below. + +``` +www/ +├── build/ +│ ├── assets/ +│ │ ├── logo.png +│ │ └── scenery/ +│ │ ├── beach.png +│ │ └── sunset.png +│ └── other-assets/ +│ └── font.tiff +└── ... +``` + +To resolve the path to an asset, Stencil's [`getAssetPath()` API](#getassetpath) may be used. +When using `getAssetPath`, the assets in the directory structure above are resolved relative to `build/`. + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments. +The return value is a path that Stencil has built to retrieve the asset on the filesystem. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": + +// '/build/assets/logo.png' +getAssetPath('assets/logo.png'); +// '/build/assets/scenery/beach.png' +getAssetPath('assets/scenery/beach.png'); +// '/build/other-assets/font.tiff' +getAssetPath('other-assets/font.tiff'); +``` + +## Making Assets Available + +In order to be able to find assets at runtime, they need to be found on the filesystem from the output of a Stencil build. +In other words, we need to ensure they exist in the distribution directory. +This section describes how to make assets available under the asset base path. + +### assetsDirs + +The `@Component` decorator can be [configured with the `assetsDirs` option](../components/component.md#component-options). +`assetsDirs` takes an array of strings, where each entry is a relative path from the component to a directory containing the assets the component requires. + +When using the `dist` or `www` output targets, setting `assetsDirs` instructs Stencil to copy that folder into the distribution folder. +When using other output targets, Stencil will not copy assets into the distribution folder. + +Below is an example project's directory structure containing an example component and an assets directory. + +``` +src/ +└── components/ + ├── assets/ + │ ├── beach.jpg + │ └── sunset.jpg + └── my-component.tsx +``` + +Below, the `my-component` component will correctly load the assets based on it's `image` prop. + +```tsx +// file: my-component.tsx +// 1. getAssetPath is imported from '@stencil/core' +import { Component, Prop, getAssetPath, h } from '@stencil/core'; + +@Component({ + tag: 'my-component', + // 2. assetsDirs lists the 'assets' directory as a relative + // (sibling) directory + assetsDirs: ['assets'] +}) +export class MyComponent { + + @Prop() image = "sunset.jpg"; + + render() { + // 3. the asset path is retrieved relative to the asset + // base path to use in the tag + const imageSrc = getAssetPath(`./assets/${this.image}`); + return + } +} +``` + +In the example above, the following allows `my-component` to display the provided asset: +1. [`getAssetPath()`](#getassetpath) is imported from `@stencil/core` +2. The `my-component`'s component decorator has the `assetsDirs` property, and lists the sibling directory, `assets`. This will copy `assets` over to the distribution directory. +3. `getAssetPath` is used to retrieve the path to the image to be used in the `` tag + +### Manually Moving Assets + +For the [dist-custom-elements](../output-targets/custom-elements.md) output target, options like `assetsDirs` do not copy assets to the distribution directory. + +It's recommended that a bundler (such as rollup) or a Stencil `copy` task is used to ensure the static assets are copied to the distribution directory. + +#### Stencil Copy Task + +[Stencil `copy` task](../output-targets/copy-tasks.md)s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a copy task can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```ts +import { Config } from '@stencil/core'; + +export const config: Config = { + namespace: 'your-component-library', + outputTargets: [ + { + type: 'dist-custom-elements', + copy: [ + { + src: '**/*.{jpg,png}', + dest: 'dist/components/assets', + warn: true, + } + ] + }, + ], + // ... +}; +``` +#### Rollup Configuration + +[Rollup Plugins](../config/plugins.md#rollup-plugins)'s can be used to define files and folders to be copied over to the distribution directory. + +The example below shows how a the `rollup-plugin-copy` NPM module can be used to find all '.jpg' and '.png' files under a project's `src` directory and copy them to `dist/components/assets` at build time. + +```javascript +import { Config } from '@stencil/core'; +import copy from 'rollup-plugin-copy'; + +export const config: Config = { + namespace: 'copy', + outputTargets: [ + { + type: 'dist-custom-elements', + }, + ], + rollupPlugins: { + after: [ + copy({ + targets: [ + { + src: 'src/**/*.{jpg,png}', + dest: 'dist/components/assets', + }, + ], + }), + ] + } +}; +``` + +## API Reference + +### getAssetPath + +`getAssetPath()` is an API provided by Stencil to build the path to an asset, relative to the asset base path. + +```ts +/** + * Builds a URL to an asset. This is achieved by combining the + * provided `path` argument with the base asset path. + * @param path the path of the asset to build a URL to + * @returns the built URL + */ +declare function getAssetPath(path: string): string; +``` + +The code sample below demonstrates the return value of `getAssetPath` for different `path` arguments, when an asset base path of `/build/` has been set. +```ts +import { getAssetPath } from '@stencil/core'; + +// with an asset base path of "/build/": +// "/build/" +getAssetPath(''); +// "/build/my-image.png" +getAssetPath('my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('assets/my-image.png'); +// "/build/assets/my-image.png" +getAssetPath('./assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('../assets/my-image.png'); +// "/assets/my-image.png" +getAssetPath('/assets/my-image.png'); +``` + +### setAssetPath + +`setAssetPath` is an API provided by Stencil's runtime to manually set the asset base path where assets can be found. If you are using `getAssetPath` to compose the path for your component assets, `setAssetPath` allows you or the consumer of the component to change that path. + +```ts +/** + * Set the base asset path for resolving components + * @param path the base asset path + * @returns the new base asset path + */ +export declare function setAssetPath(path: string): string; +``` + +Calling this API will set the asset base path for all Stencil components attached to a Stencil runtime. As a result, calling `setAssetPath` should not be done from within a component in order to prevent unwanted side effects when using a component. + +Make sure as component author to export this function as part of your module in order to also make it accessible to the consumer of your component, e.g. in your package entry file export the function via: + +```ts title="/src/index.ts" +export { setAssetPath } from '@stencil/core'; +``` + +Now your users can import it directly from your component library, e.g.: + +```ts +import { setAssetPath } from 'my-component-library'; +setAssetPath(`${window.location.protocol}//assets.${window.location.host}/`); +``` + +Alternatively, one may use [`document.currentScript.src`](https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript) when working in the browser and not using modules or environment variables (e.g. `document.env.ASSET_PATH`) to set the +asset base path. This configuration depends on how your script is bundled, (or lack of bundling), and where your assets can be loaded from. + +:::note + +If your component library exports components compiled with [`dist-output-target`](/output-targets/custom-elements.md) and `externalRuntime` set to `true`, then `setAssetPath` has to be imported from `@stencil/core` directly. + +::: + +In case you import a component directly via script tag, this would look like: + +```html + + + + + + + + + +``` diff --git a/versioned_docs/version-v4.20/guides/build-conditionals.md b/versioned_docs/version-v4.20/guides/build-conditionals.md new file mode 100644 index 000000000..0f540e8de --- /dev/null +++ b/versioned_docs/version-v4.20/guides/build-conditionals.md @@ -0,0 +1,41 @@ +--- +title: Build Conditionals +description: Build Conditionals +--- + +# Build Conditionals + +Build Conditionals in Stencil allow you to run specific code only when Stencil is running in development mode. This code is stripped from your bundles when doing a production build, therefore keeping your bundles as small as possible. + +### Using Build Conditionals + +Lets dive in and look at an example of how to use our build conditional: + +```tsx +import { Component, Build } from '@stencil/core'; + +@Component({ + tag: 'stencil-app', + styleUrl: 'stencil-app.css' +}) +export class StencilApp { + + componentDidLoad() { + if (Build.isDev) { + console.log('im in dev mode'); + } else { + console.log('im running in production'); + } + } +} +``` + +As you can see from this example, we just need to import `Build` from `@stencil/core` and then we can use the `isDev` constant to detect when we are running in dev mode or production mode. + +### Use Cases + +Some use cases we have come up with are: + +- Diagnostics code that runs in dev to make sure logic is working like you would expect +- `console.log()`'s that may be useful for debugging in dev mode but that you don't want to ship +- Disabling auth checks when in dev mode diff --git a/versioned_docs/version-v4.20/guides/csp-nonce.md b/versioned_docs/version-v4.20/guides/csp-nonce.md new file mode 100644 index 000000000..e18636cd8 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/csp-nonce.md @@ -0,0 +1,119 @@ +--- +title: Content Security Policy Nonces +description: How to leverage CSP nonces in Stencil projects. +slug: /csp-nonce +--- + +# Using Content Security Policy Nonces in Stencil + +[Content Security Policies (CSPs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) can help protect an application from Cross-Site Scripting (XSS) +attacks by adding a security layer to help prevent unauthorized code from running in the browser. + +An application that is served with a CSP other than 'unsafe-inline' and contains web components without a Shadow DOM will likely run into errors on load. +This is often first detected in the browser's console, which reports an error stating that certain styles or scripts violate the effective CSP. + +To resolve this issue, Stencil supports using [CSP nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) in +many of the output targets. + +:::caution +NOTE: CSPs and some CSP strategies are not supported by certain browsers. For a more detailed list, please see the [CSP browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#browser_compatibility). +::: + +## How to Use a Nonce + +The actual generation of the nonce value and enforcement of the correct CSP are not the responsibility of Stencil. Instead, the server of +the application will need to generate the nonce value for each page view, construct the CSP, and then correctly handle passing the generated nonce to +Stencil based on which output target is being consumed. + +There are many resources available that walk through setting up a CSP and using the nonce behavior. +[This](https://towardsdatascience.com/content-security-policy-how-to-create-an-iron-clad-nonce-based-csp3-policy-with-webpack-and-nginx-ce5a4605db90) +article walks through the process using Nginx and Webpack. Obviously, these resources don't account for the Stencil specifics, but any specifics will +be called out in this guide. + +Per the [MDN Guide on nonces](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce#generating_values), a nonce should be "a random base64-encoded string of at least 128 bits of data from a cryptographically secure random number generator". + +### Output Targets + +Using nonces may differ slightly between output targets, so please be sure to use the correct pattern based on the context in which your +Stencil components are consumed. + +#### Dist + +Consuming a `nonce` in the `dist` output target is easy using the provided `setNonce` helper function. This function is exported from the index +file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); + +defineCustomElements(); +``` + +#### Custom Elements + +Consuming a `nonce` in the `dist-custom-elements` output target is easy using the provided `setNonce` helper function. This function is exported +from the index file of the output target's designated output directory. + +This function simply accepts the `nonce` string value that you want set for every `style` and `script` tag. + +This is an example of consuming the `dist-custom-elements` output in an Angular app's entrypoint: + +```ts +// main.ts + +import { defineCustomElements, setNonce } from 'my-lib/dist/components'; +// Assume `customElementsExportBehavior: 'auto-define-custom-elements'` is set +import 'my-lib/dist/components/my-component'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +// Generic Angular bootstrapping +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => console.log(err)); +``` + +#### WWW + +Unfortunately, setting `nonce` attributes gets a bit trickier when it comes to [SSR and SSG](../static-site-generation/01-overview.md). As a `nonce` needs +to be unique per page view, it cannot be defined/set at build time. So, this responsibility now falls on the +[hydrate app](../guides/hydrate-app.md)'s execution of runtime code. + +**SSR** + +Since there is not an easy way (or any way) of exposing and executing helper functions to manipulate the outcome of the runtime code, Stencil +has fallback behavior for pulling the `nonce` off of a `meta` tag in the DOM head. + +So, for SSR, your app can simply inject a `meta` element into the header _on each page request_. Yes, this does involve some manual configuration +for the code served by your server. To work correctly, the created tag must be generated as follows: + +```html + +``` + +This isn't a security risk because, for an attacker to execute a script to pull the nonce from the meta tag, they would have needed to know the +nonce _ahead_ of the script's execution. + +**SSG** + +Stencil cannot support CSP nonces with SSG. Because all of the code is generated during [pre-rendering](../static-site-generation/01-overview.md#how-static-site-generation-and-prerendering-works), Stencil doesn't generate the `style` or `script` tags at runtime. +If an application wants to leverage nonces in SSG, they can build a mechanism to scrape the pre-rendered code and apply the attribute server-side before +it is served to the client. diff --git a/versioned_docs/version-v4.20/guides/design-systems.md b/versioned_docs/version-v4.20/guides/design-systems.md new file mode 100644 index 000000000..356f9dcbc --- /dev/null +++ b/versioned_docs/version-v4.20/guides/design-systems.md @@ -0,0 +1,77 @@ +--- +title: Design Systems +sidebar_label: Design Systems +description: Design Systems in Stencil +slug: /design-systems +--- + +# Design Systems + +## What is a Design System? + +A Design System consists of UI components and a clearly defined visual style, released as both code implementations and design artifacts. +When adopted by all product teams, a more cohesive customer experience emerges. + +There are several aspects that Design Systems consist of: + +### Components +A component is a standalone UI element designed to be reusable across many projects. +Its goal is to do one thing well, while remaining abstract enough to allow for a variety of use cases. +Developers can use them as building blocks to build new user experiences. +One of the key benefits of reusable components is that developers don't have to worry about the core design and functionality of each component every time they use them. +Examples include buttons, links, forms, input fields, and modals. + +### Patterns +A pattern is an opinionated use of components. +Often, multiple components are combined in order to create a standardized user experience (UX). +As a result, they improve both the user and developer experience. +After implementing patterns, users will understand the application better and accomplish their tasks faster. +When the development team understands the proper way to use components together, software applications become easier to use. +Examples include saving data to the system, capturing data from forms, and filtering and analyzing data. + +### Visual Language +A cohesive company brand strengthens its value in the minds of the customer. +In the context of design systems, this means defining various aspects of the visual style, including colors, typography, and icons. +Defining primary, secondary, and tertiary colors helps an application stand out and is more user-friendly. +The right typography ensures users are not distracted while using an app. +Finally, icons increase engagement in a product and make it “pop” visually. + +### Design Artifacts and Code Implementations +By leveraging the components, patterns, and visual language of the design system, designers can create design artifacts representing UI workflows. +Developers refer to the artifacts as guidance for implementing the design with code. + +## The Value of Design Systems +With a design system in place, its true value is revealed. +The entire product development team is freed up to focus on what matters most: solving customer problems and delivering value. +Additionally, the avoidance of having teams working in parallel, recreating the same UI elements over and over, has a real-world project impact in terms of reduced time to market and increased cost savings. + +Design systems allow project teams to work better together. +Designers define a centralized “source of truth” for software application best practices which can be referenced by anyone in a product organization. +Developers no longer need to spend time rethinking how to build common app scenarios, such as application search or data table grids. +When the business inevitably makes changes to the design system, they can easily be applied to all projects. +The end result is a better product for your users. + +## Using Stencil to Build a Design System + +There’s a lot that goes into creating amazing UI components. +Performance, accessibility, cross-platform capabilities, and user experience (not only of the UI component itself but how it fits into the entire design system) all must be considered. + +These aspects take real effort to do well. + +Enter Stencil, a robust and highly extensible tool for building components and patterns, the building blocks of a design system. +With its intentionally minimalistic tooling and API footprint, it’s simple to incorporate into your existing development workflows. +It brings substantial performance out of the box by leveraging a tiny runtime. +Most importantly, all UI components built with Stencil are based 100% on open web standards. + +### The Importance of Open Web Standards +By using the web components standard, supported in all modern browsers, Stencil-built UI components offer many distinct advantages for use in a design system, namely: + +* They work on any platform or device +* They work with any front-end framework, so they can easily be used across teams and projects using different tech stacks +* They facilitate the creation of one company-wide code implementation instead of one per framework or platform + +Learn more about why web components are ideal for design systems in [this blog post](https://blog.ionicframework.com/5-reasons-web-components-are-perfect-for-design-systems/). + +### How to Get Started +Stencil’s out-the-box features will help you build your own library of universal UI components that will work across platforms, devices, and front-end frameworks. +Review the documentation on this site to get started. diff --git a/versioned_docs/version-v4.20/guides/forms.md b/versioned_docs/version-v4.20/guides/forms.md new file mode 100644 index 000000000..555162b98 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/forms.md @@ -0,0 +1,165 @@ +--- +title: Forms +sidebar_label: Forms +description: Forms +slug: /forms +--- + +# Forms + +## Basic forms + +Here is an example of a component with a basic form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + + @State() value: string; + + handleSubmit(e) { + e.preventDefault() + console.log(this.value); + // send data to our backend + } + + handleChange(event) { + this.value = event.target.value; + } + + render() { + return ( +
    this.handleSubmit(e)}> + + +
    + ); + } +} +``` + +Let's go over what is happening here. First we bind the value of the input to a state variable, in this case `this.value`. We then set our state variable to the new value of the input with the `handleChange` method we have bound to `onInput`. `onInput` will fire every keystroke that the user types into the input. + +## Using form-associated custom elements + +In addition to using a `
    ` element inside of a Stencil component, as shown +in the above example, you can also use Stencil's support for building +form-associated custom elements to create a Stencil component that integrates +in a native-like way with a `` tag _around_ it. This allows you to build +rich form experiences using Stencil components which leverage built-in form +features like validation and accessibility. + +As an example, translating the above example to be a form-associated component +(instead of one which includes a `` element in its JSX) would look like +this: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css', + formAssociated: true +}) +export class MyName { + @State() value: string; + @AttachInternals() internals: ElementInternals; + + handleChange(event) { + this.internals.setFormValue(event.target.value); + } + + render() { + return ( + + ); + } +} +``` + +For more check out the docs for [form-association in Stencil](../components/form-associated.md). + +## Advanced forms + +Here is an example of a component with a more advanced form: + +```tsx +@Component({ + tag: 'my-name', + styleUrl: 'my-name.css' +}) +export class MyName { + selectedReceiverIds = [102, 103]; + @State() value: string; + @State() selectValue: string; + @State() secondSelectValue: string; + @State() avOptions: any[] = [ + { 'id': 101, 'name': 'Mark' }, + { 'id': 102, 'name': 'Smith' } + ]; + + handleSubmit(e) { + e.preventDefault(); + console.log(this.value); + } + + handleChange(event) { + this.value = event.target.value; + + if (event.target.validity.typeMismatch) { + console.log('this element is not valid') + } + } + + handleSelect(event) { + console.log(event.target.value); + this.selectValue = event.target.value; + } + + handleSecondSelect(event) { + console.log(event.target.value); + this.secondSelectValue = event.target.value; + } + + render() { + return ( + this.handleSubmit(e)}> + + + + + + + +
    + ); + } +} +``` + +This form is a little more advanced in that it has two select inputs along with an email input. We also do validity checking of our email input in the `handleChange` method. We handle the `select` element in a very similar manner to how we handle text inputs. + +For the validity checking, we are #usingtheplatform and are using the [constraint validation api](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation) that is built right into the browser to check if the user is actually entering an email or not. diff --git a/versioned_docs/version-v4.20/guides/hydrate-app.md b/versioned_docs/version-v4.20/guides/hydrate-app.md new file mode 100644 index 000000000..37fd5c7af --- /dev/null +++ b/versioned_docs/version-v4.20/guides/hydrate-app.md @@ -0,0 +1,248 @@ +--- +title: Hydrate App +sidebar_label: Hydrate App +description: Hydrate App +slug: /hydrate-app +--- + +# Hydrate App + +The hydrate app is a Stencil output target which generates a module that can be +used on a NodeJS server to hydrate HTML and implement server side rendering (SSR). +This functionality is used internally by the Stencil compiler for +prerendering, as well as for the Angular Universal SSR for the Ionic +framework. However, like Stencil components, the hydrate app itself is not +restricted to one framework. + +_Note that Stencil does **NOT** use Puppeteer for SSR or prerendering._ + +## How to Use the Hydrate App + +Server side rendering (SSR) can be accomplished in a similar way to +prerendering. Instead of using the `--prerender` CLI flag, you can an output +target of type `'dist-hydrate-script'` to your `stencil.config.ts`, like so: + +```ts +outputTargets: [ + { + type: 'dist-hydrate-script', + }, +]; +``` + +This will generate a `hydrate` app in your root project directory that can be +imported and used by your Node server. + +After publishing your component library, you can import the hydrate app into +your server's code like this: + +```javascript +import { hydrateDocument, renderToString, streamToString } from 'yourpackage/hydrate'; +``` + +The hydrate app module exports 3 functions, `hydrateDocument`, `renderToString` and `streamToString`. `hydrateDocument` takes a [document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) as its input while `renderToString` as well as `streamToString` takes a raw HTML string. While `hydrateDocument` and `renderToString` return a Promise which wraps a result object, `streamToString` returns a [`Readable`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) stream that can be passed into a server response. + +### hydrateDocument + +You can use `hydrateDocument` as a part of your server's response logic before +serving the web page. `hydrateDocument` takes two arguments, a +[document](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument) and a +config object. The function returns a promise with the hydrated results, with +the hydrated HTML under the `html` property. + +*Example taken from Ionic Angular server* + + ```javascript +import { hydrateDocument } from 'yourpackage/hydrate'; + +export function hydrateComponents(doc) { + return hydrateDocument(doc) + .then((hydrateResults) => { + // execute logic based on results + console.log(hydrateResults.html); + return hydrateResults; + }); +} +``` + +#### hydrateDocument Options + + - `canonicalUrl` - string + - `constrainTimeouts` - boolean + - `clientHydrateAnnotations` - boolean + - `cookie` - string + - `direction` - string + - `language` - string + - `maxHydrateCount` - number + - `referrer` - string + - `removeScripts` - boolean + - `removeUnusedStyles` - boolean + - `resourcesUrl` - string + - `timeout` - number + - `title` - string + - `url` - string + - `userAgent` - string + +### renderToString + +The hydrate app also has a `renderToString` function that takes an HTML string +and returns a promise of `HydrateResults`. The optional second parameter is a +config object that can alter the output of the markup. Like `hydrateDocument`, +the hydrated HTML can be found under the `html` property. + +*Example taken from Ionic Core* + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ +``` + +#### renderToString Options + +##### `approximateLineWidth` + +__Type:__ `number` + +Determines when line breaks are being set when serializing the component. + +##### `prettyHtml` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` it prettifies the serialized HTML code, intends elements and escapes text nodes. + +##### `removeAttributeQuotes` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes attribute quotes when possible, e.g. replaces `someAttribute="foo"` to `someAttribute=foo`. + +##### `removeEmptyAttributes` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true` it removes attribute that don't have values, e.g. remove `class=""`. + +##### `removeHtmlComments` + +__Type:__ `boolean` + +__Default:__ `false` + +If set to `true` it removes any abundant HTML comments. Stencil still requires to insert hydration comments to be able to reconcile the component. + +##### `beforeHydrate` + +__Type:__ `(document: Document, url: URL) => | Promise` + +Allows to modify the document and all its containing components to be modified before the hydration process starts. + +##### `afterHydrate` + +__Type:__ `(document: Document, url: URL, results: PrerenderUrlResults) => | Promise` + +Allows to modify the document and all its containing components after the component was rendered in the virtual DOM and before the serialization process starts. + +##### `serializeShadowRoot` + +__Default:__ `false` + +__Type:__ `boolean` + +If set to `true` Stencil will render a component defined with a `shadow: true` flag into a [Declarative Shadow DOM](https://developer.chrome.com/docs/css-ui/declarative-shadow-dom), e.g.: + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: true, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + * + * + * ``` + */ +``` + +```javascript +const results = await hydrate.renderToString( + ``, + { + fullDocument: false, + serializeShadowRoot: false, + prettyHtml: true, + } +); + +console.log(results.html); +/** + * outputs: + * ```html + * + * + *
    + * + * Hello, World! I'm Stencil 'Don't call me a framework' JS + *
    + *
    + * ``` + */ +``` + +If set to `false` it renders the component as scoped component. + +##### `fullDocument` + +__Type:__ `boolean` + +__Default:__ `true` + +If set to `true`, Stencil will serialize a complete HTML document for a server to respond. If set to `false` it will only render the components within the given template. diff --git a/versioned_docs/version-v4.20/guides/module-bundling.md b/versioned_docs/version-v4.20/guides/module-bundling.md new file mode 100644 index 000000000..769bea76b --- /dev/null +++ b/versioned_docs/version-v4.20/guides/module-bundling.md @@ -0,0 +1,150 @@ +--- +title: Module Bundling +sidebar_label: Bundling +description: Module Bundling +slug: /module-bundling +--- + +# Module Bundling + +Stencil uses [Rollup](https://rollupjs.org/guide/en/) under the hood to bundle your components. This guide will explain and recommend certain workarounds for some of the most common bundling issues you might encounter. + +## One Component Per Module + +For Stencil to bundle your components most efficiently, you must declare a single component (class decorated with `@Component`) per *TypeScript* file, and the component itself **must** have a unique `export`. By doing so, Stencil is able to easily analyze the entire component graph within the app, and best understand how components should be bundled together. Under-the-hood it uses the Rollup bundler to efficiently bundled shared code together. Additionally, lazy-loading is a default feature of Stencil, so code-splitting is already happening automatically, and only dynamically importing components which are being used on the page. + +Modules that contain a component are entry-points, which means that no other module should import anything from them. + +The following example is **NOT** valid: + +```tsx title="src/components/my-cmp.tsx" +// This module has a component, you cannot export anything else +export function someUtilFunction() { + console.log('do stuff'); +} + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +In this case, the compiler will emit an error that looks like this: + +```bash +[ ERROR ] src/components/my-cmp.tsx:4:1 + To allow efficient bundling, modules using @Component() can only have a single export which is the component + class itself. Any other exports should be moved to a separate file. For further information check out: + https://stenciljs.com/docs/module-bundling + + L4: export function someUtilFunction() { + L5: console.log('do stuff'); +``` + +The solution is to move any shared functions or classes to a different `.ts` file, like this: + +```tsx title="src/utils.ts" +export function someUtilFunction() { + console.log('do stuff'); +} +``` + +```tsx title="src/components/my-cmp.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp' +}) +export class MyCmp {} +``` + +```tsx title="src/components/my-cmp-two.tsx" +import { someUtilFunction } from '../utils.ts'; + +@Component({ + tag: 'my-cmp-two' +}) +export class MyCmpTwo {} +``` + + +## CommonJS Dependencies + +Rollup depends on [ES modules (ESM)](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) to properly tree-shake the module graph, unfortunately, some third-party libraries ship their code using the [CommonJS](https://requirejs.org/docs/commonjs.html) module system, which is not ideal. + +Since CommonJS libraries are still common today, Stencil comes with [`rollup-plugin-commonjs`](https://github.com/rollup/rollup-plugin-commonjs) already installed and configured. + +At compiler-time, the `rollup-plugin-commonjs` plugin does a best-effort to **transform CommonJS into ESM**, but this is not always an easy task. CommonJS is dynamic by nature, while ESM is static by design. + +For further information, check out the [rollup-plugin-commonjs docs](https://github.com/rollup/plugins/tree/master/packages/commonjs). + + + +## Custom Rollup plugins + +Stencil provides an API to pass custom rollup plugins to the bundling process in `stencil.config.ts`. Under the hood, stencil ships with some built-in plugins including `node-resolve` and `commonjs`, since the execution order of some rollup plugins is important, stencil provides an API to inject custom plugin **before node-resolve** and after **commonjs transform**: + +```tsx +export const config = { + rollupPlugins: { + before: [ + // Plugins injected before rollupNodeResolve() + resolvePlugin() + ], + after: [ + // Plugins injected after commonjs() + nodePolyfills() + ] + } +} +``` + +As a rule of thumb, plugins that need to resolve modules, should be place in `before`, while code transform plugins like: `node-polyfills`, `replace`... should be placed in `after`. Follow the plugin's documentation to make sure it's executed in the right order. + + +## Node Polyfills + +Depending on which libraries a project is dependent on, the [rollup-plugin-node-polyfills](https://www.npmjs.com/package/rollup-plugin-node-polyfills) plugin may be required. In such cases, an error message similar to the following will be displayed at build time. + +```bash +[ ERROR ] Bundling Node Builtin + For the import "crypto" to be bundled from 'problematic-dep', + ensure the "rollup-plugin-node-polyfills" plugin is installed + and added to the stencil config plugins. +``` + +This is caused by some third-party dependencies that use [Node APIs](https://nodejs.org/dist/latest-v10.x/docs/api/) that are not available in the browser, the `rollup-plugin-node-polyfills` plugin works by transparently polyfilling this missing APIs in the browser. + +### 1. Install `rollup-plugin-node-polyfills`: + +```bash npm2yarn +npm install rollup-plugin-node-polyfills --save-dev +``` + +### 2. Update the `stencil.config.ts` file including the plugin: + +```tsx +import { Config } from '@stencil/core'; +import nodePolyfills from 'rollup-plugin-node-polyfills'; + +export const config: Config = { + namespace: 'mycomponents', + rollupPlugins: { + after: [ + nodePolyfills(), + ] + } +}; +``` + +:::note +`rollup-plugin-node-polyfills` is a code-transform plugin, so it needs to run AFTER the commonjs transform plugin, that's the reason it's placed in the "after" array of plugins. +::: + +## Strict Mode + +ES modules are always parsed in strict mode. That means that certain non-strict constructs (like octal literals) will be treated as syntax errors when Rollup parses modules that use them. Some older CommonJS modules depend on those constructs, and if you depend on them your bundle will blow up. There's nothing we can do about that. + +Luckily, there is absolutely no good reason not to use strict mode for everything — so the solution to this problem is to lobby the authors of those modules to update them. + +*Source: [https://github.com/rollup/rollup-plugin-commonjs#strict-mode](https://github.com/rollup/rollup-plugin-commonjs#strict-mode)* diff --git a/versioned_docs/version-v4.20/guides/publishing.md b/versioned_docs/version-v4.20/guides/publishing.md new file mode 100644 index 000000000..1c4acdf01 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/publishing.md @@ -0,0 +1,159 @@ +--- +title: Publishing A Component Library +sidebar_label: Publishing +description: Publishing A Component Library +slug: /publishing +--- + +There are numerous strategies to publish and distribute your component library to be consumed by external projects. One of the benefits of Stencil is that is makes it easy to generate the various [output targets](../output-targets/01-overview.md) that are right for your use-case. + +## Use Cases + +To use your Stencil components in other projects, there are two different output targets to consider: [`dist`](../output-targets/dist.md) and [`dist-custom-elements`](../output-targets/custom-elements.md). Both export your components for different use cases. Luckily, both can be generated at the same time, using the same source code, and shipped in the same distribution. It would be up to the consumer of your component library to decide which build to use. + +### Lazy Loading + +If you prefer to have your components automatically loaded when used in your application, we recommend enabling the [`dist`](../output-targets/dist.md) output target. The bundle gives you a small entry file that registers all your components and defers loading the full component logic until it is rendered in your application. It doesn't matter if the actual application is written in HTML or created with vanilla JavaScript, jQuery, React, etc. + +Your users can import your component library, e.g. called `my-design-system`, either via a `script` tag: + +```html + +``` + +or by importing it in the bootstrap script of your application: + +```ts +import 'my-design-system'; +``` + +To ensure that the right entry file is loaded when importing the project, define the following fields in your `package.json`: + +```json +{ + "exports": "./dist/esm/my-design-system.js", + "main": "./dist/cjs/my-design-system.js", + "unpkg": "dist/my-design-system/my-design-system.esm.js", +} +``` + +Read more about various options when it comes to configuring your project's components for lazy loading in the [`dist`](../output-targets/dist.md) output target section. + +#### Considerations + +To start, Stencil was designed to lazy-load itself only when the component was actually used on a page. There are many benefits to this approach, such as simply adding a script tag to any page and the entire library is available for use, yet only the components actually used are downloaded. For example, [`@ionic/core`](https://www.npmjs.com/package/@ionic/core) comes with over 100 components, but a webpage may only need `ion-toggle`. Instead of requesting the entire component library, or generating a custom bundle for just `ion-toggle`, the `dist` output target is able to generate a tiny entry build ready to load any of its components on-demand. + +However be aware that this approach is not ideal in all cases. It requires your application to ship the bundled components as static assets in order for them to load properly. Furthermore, having many nested component dependencies can have an impact on the performance of your application. For example, given you have a component `CmpA` which uses a Stencil component `CmpB` which itself uses another Stencil component `CmpC`. In order to fully render `CmpA` the browser has to load 3 scripts sequentially which can result in undesired rendering delays. + +### Standalone + +The [`dist-custom-elements`](../output-targets/custom-elements.md) output target builds each component as a stand-alone class that extends `HTMLElement`. The output is a standardized custom element with the styles already attached and without any of Stencil's lazy-loading. This may be preferred for projects that are already handling bundling, lazy-loading and defining the custom elements themselves. + +The generated files will each export a component class and will already have the styles bundled. However, this build does not define the custom elements or apply any polyfills. Static assets referenced within components will need to be set using `setAssetPath` (see [Making Assets Available](../output-targets/custom-elements.md#making-assets-available)). + +You can use these standalone components by importing them via: + +```ts +import { MyComponent, defineCustomElementMyComponent } from 'my-design-system' + +// register to CustomElementRegistry +defineCustomElementMyComponent() + +// or extend custom element via +class MyCustomComponent extends MyComponent { + // ... +} +define('my-custom-component', MyCustomComponent) +``` + +To ensure that the right entry file is loaded when importing the project, define different [exports fields](https://nodejs.org/api/packages.html#exports) in your `package.json`: + +```json +{ + "exports": { + ".": { + "import": "./dist/components/index.js", + "types": "./dist/components/index.d.ts" + }, + "./my-component": { + "import": "./dist/components/my-component.js", + "types": "./dist/components/my-component.d.ts" + } + }, + "types": "dist/components/index.d.ts", +} +``` + +This allows us to map certain import paths to specific components within our project and allows users to only import the component code they are interested in and reduce the amount of code that needs to downloaded by the browser, e.g.: + +```js +// this import loads all compiled components +import { MyComponent } from 'my-design-system' +// only import compiled code for MyComponent +import { MyComponent } from 'my-design-system/my-component' +``` + +If you define exports targets for all your components as shown above and by using [`customElementsExportBehavior: 'auto-define-custom-elements'`](../output-targets/custom-elements.md#customelementsexportbehavior) as output target option, you can skip the `defineCustomElement` call and directly import the component where you need it: + +```ts +import 'my-design-system/my-component' +``` + +:::note +If you are distributing both the `dist` and `dist-custom-elements`, then it's best to pick one of them as the main entry depending on which use case is more prominent. +::: + +Read more about various options when it comes to distributing your components as standalone components in the [`dist-custom-elements`](../output-targets/custom-elements.md) output target section. + +The output directory will also contain an `index.js` file which exports some helper methods by default. The contents of the file will look something like: + +```js +export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client'; +``` + +:::note +The contents may look different if [`customElementsExportBehavior`](../output-targets/custom-elements.md#customelementsexportbehavior) is specified! +::: + +#### Considerations + +The `dist-custom-elements` is a direct build of the custom element that extends `HTMLElement`, without any lazy-loading. This distribution strategy may be preferred for projects that use an external bundler such as [Vite](https://vitejs.dev/), [WebPack](https://webpack.js.org/) or [Rollup](https://rollupjs.org) to compile the application. They ensure that only the components used within your application are bundled into compilation. + +#### Usage in TypeScript + +If you plan to support consuming your component library in TypeScript you'll need to set `generateTypeDeclarations: true` on the output target in your `stencil.config.ts`, like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + generateTypeDeclarations: true, + }, + // ... + ], + // ... +}; +``` + +Then you can set the `types` property in `package.json` so that consumers of your package can find the type definitions, like so: + +```json title="package.json" +{ + "types": "dist/components/index.d.ts", + "dependencies": { + "@stencil/core": "latest" + }, + ... +} +``` + +:::note +If you set the `dir` property on the output target config, replace `dist/components` in the above snippet with the path set in the config. +::: + +## Publishing to NPM + +[NPM](https://www.npmjs.com/) is an online software registry for sharing libraries, tools, utilities, packages, etc. To make your Stencil project widely available to be consumed, it's recommended to [publish the component library to NPM](https://docs.npmjs.com/getting-started/publishing-npm-packages). Once the library is published to NPM, other projects are able to add your component library as a dependency and use the components within their own projects. diff --git a/versioned_docs/version-v4.20/guides/service-workers.md b/versioned_docs/version-v4.20/guides/service-workers.md new file mode 100644 index 000000000..51f37237a --- /dev/null +++ b/versioned_docs/version-v4.20/guides/service-workers.md @@ -0,0 +1,293 @@ +--- +title: Service Workers +sidebar_label: Service Workers +description: Service Workers +slug: /service-workers +--- + +# Service Workers + +[Service workers](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers) are a very powerful api that is essential for [PWAs](https://blog.ionic.io/what-is-a-progressive-web-app/), but can be hard to use. To help with this, we decided to build support for Service Workers into Stencil itself using [Workbox](https://workboxjs.org/). + +## What is Workbox? + +Workbox is a library that greatly simplifies the Service Worker API. It allows you to quickly generate a service worker that can handle caching static assets, cache remote assets using routes (similar to Express) or even do offline Google Analytics. Because we are built on top of Workbox, you can easily use any of the functionality they offer. For more info on Workbox, [check out their docs](https://developers.google.com/web/tools/workbox/) + +## Usage + +When doing a production build of an app built using Stencil, the Stencil compiler will automatically generate a service worker for you and inject the necessary code to register the service worker in your index.html. Also, because the files Stencil generates are hashed, every time you do a production build and push an update to your app, the service worker will know to update, therefore ensuring your users are never stuck on a stale version of your site. + +Lets run through the steps needed to enable service workers for your project: + +- `cd` into your project +- Run `npm run build` + +And that's it! You should now have an `sw.js` file in your `www` folder and the code to register the service worker in your `www/index.html` file. + +:::note +The component starter by default does not have service workers enabled as a service worker is not needed for component collections +::: + +## Config + +Stencil uses Workbox underneath, and by default generates a service worker from a config object using the `generateSW` mode. Therefore it supports all of the [Workbox generateSW config options](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). Here is the default config Stencil uses: + +```tsx +{ + globPatterns: [ + '**/*.{js,css,json,html}' + ] +}; +``` + +This configuration does pre-caching of all of your app's assets. + +To modify this config you can use the `serviceWorker` param of your Stencil config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + globPatterns: [ + '**/*.{js,css,json,html,ico,png}' + ] + } + } + ] +}; +``` + +### Disabling the service worker + +If you do not want a service worker to be generated during the build, this can be turned off. To disable this feature, set the `serviceWorker` property to `null` in the `www` output target. + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: null + } + ] +}; +``` + +## Using a custom service worker + +Already have a service worker or want to include some custom code? We support that, too. By specifying a source file for your service worker, Stencil switches to the `injectManifest` mode of Workbox. That gives you full control over your service worker, while still allowing you to automatically inject a precache manifest. + +Let's go through the steps needed for this functionality: + +- First we need to pass the path to our custom service worker to the `swSrc` command in the `serviceWorker` config. Here is an example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + serviceWorker: { + swSrc: 'src/sw.js' + } + } + ] +}; +``` + +- Now we need to include some boilerplate code in our custom service worker: + +```tsx +// change to the version you get from `npm ls workbox-build` +importScripts('workbox-v4.3.1/workbox-sw.js'); + +// your custom service worker code + +// the precache manifest will be injected into the following line +self.workbox.precaching.precacheAndRoute([]); +``` + +This code imports the Workbox library, creates a new instance of the service worker and tells Workbox where to insert the pre-cache array. + +### Showing a reload toast when an update is available + +When a new service worker is available, by default, it will be downloaded and then go into a state of waiting to be activated. The new service worker won't take over until all tabs of the site are closed and the site is visited again. This is to avoid unexpected behavior from conflicts with files being served from cache, and works well in many cases. + +If you want to give your users the option to immediately access the new update, a common way is to show them a toast that lets them know about the update and offers a "reload" button. The reload let's the new service worker take over, serving the fresh content, and triggers a page reload, to avoid cache issues. + +The following example showcases this in combination with the Ionic framework, but the toast-related code should be easily adaptable to any UI. Add the following to your root component (commonly `app-root.tsx`). + +```tsx +@Listen("swUpdate", { target: 'window' }) +async onServiceWorkerUpdate() { + const registration = await navigator.serviceWorker.getRegistration(); + + if (!registration?.waiting) { + // If there is no waiting registration, this is the first service + // worker being installed. + return; + } + + const toast = await toastController.create({ + message: "New version available.", + buttons: [{ text: 'Reload', role: 'reload' }], + duration: 0 + }); + + await toast.present(); + + const { role } = await toast.onWillDismiss(); + + if (role === 'reload') { + registration.waiting.postMessage("skipWaiting"); + } +} +``` + +The `swUpdate` event is emitted by Stencil every time a new service worker is installed. When a service worker is waiting for registration, the toast is shown. After clicking the reload button, a message is posted to the waiting service worker, letting it know to take over. This message needs to be handled by the service worker; therefore we need to create a custom one (e. g. `src/sw.js`) and add a listener to call `skipWaiting()`. + +```tsx +importScripts("workbox-v4.3.1/workbox-sw.js"); + +self.addEventListener("message", ({ data }) => { + if (data === "skipWaiting") { + self.skipWaiting(); + } +}); + +self.workbox.precaching.precacheAndRoute([]); +``` + +:::note +Don't forget to set `swSrc` in your Stencil config. +::: + +Finally, we want our app to reload when the new service worker has taken over, so that no outdated code is served from the cache anymore. We can use the service worker's `controllerchange` event for that, by attaching an event listener in our root component's `componentWillLoad` lifecycle hook. + +```tsx +componentWillLoad() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker + .getRegistration() + .then(registration => { + if (registration?.active) { + navigator.serviceWorker.addEventListener( + 'controllerchange', + () => window.location.reload() + ); + } + }) + } +} +``` + +### Handle push events + +A common use case for custom service workers is to handle browser push notifications. But before we will be able show push notifications, we first need to use the Notifications API to request permissions from the user to do so. + +```tsx +if ('Notification' in window && 'serviceWorker' in navigator) { + Notification.requestPermission(status => { + // status will either be 'default', 'granted' or 'denied' + console.log(`Notification permissions have been ${status}`); + }); +} +``` + +The current permission status can always be checked using `Notification.permission`. + +To show a notification to the user after being granted permission, we can use the `showNotification` method of our service worker's registration (within our custom service worker). + +```tsx +self.registration.showNotification('Hakuna matata.'); +``` + +Usually we will have a backend that will send out push notifications to clients, and we want our service worker to handle them. To do that, we can register an event listener in our worker for the `push` event. The event will be of type [`PushEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PushEvent) and have a `data` field of type [`PushMessageData`](https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData). + +```tsx +self.addEventListener('push', event => { + console.log(`Push received with data "${event.data.text()}"`); + + const title = 'Push Notification'; + const options = { + body: `${event.data.text()}`, + data: { href: '/users/donald' }, + actions: [ + { action: 'details', title: 'Details' }, + { action: 'dismiss', title: 'Dismiss' }, + ], + }; + + event.waitUntil(self.registration.showNotification(title, options)); +}); +``` + +If the data is a JSON string, then `data.json()` can be used to immediately get the parsed data. The `event.waitUntil` method is used to ensure that the service worker doesn't terminate before the asynchronous `showNotification` operation has completed. + +Furthermore, we will likely want to handle notification clicks. The API provides the events `notificationclick` and `notificationclose` for that. + +```tsx +self.addEventListener('notificationclick', event => { + const notification = event.notification; + const action = event.action; + + if (action === 'dismiss') { + notification.close(); + } else { + // This handles both notification click and 'details' action, + // because some platforms might not support actions. + clients.openWindow(notification.data.href); + notification.close(); + } +}); +``` + +Now our service worker is able to receive and process push notifications, however we still need to register the client with our backend. Browsers provide a push service for that reason, which your app can subscribe to. The subscription object contains an endpoint URL with a unique identifier for each client. You can send your notifications to that URL, encrypted with a public key which is also provided by the subscription object. + +In order to implement this, we first need to get each client to subscribe to the browser's push service, and then send the subscription object to our backend. Then our backend can generate the push notifications, encrypt them with the public key, and send them to the subscription endpoint URL. + +First we will implement a function to subscribe the user to the push service, which as a best practice should be triggered from a user action signalling that they would like to receive push notifications. Assuming that notification permissions have already been granted, the following function can be used for that. + +```tsx +async function subscribeUser() { + if ('serviceWorker' in navigator) { + const registration = await navigator.serviceWorker.ready; + + const subscription = await registration.pushManager + .subscribe({ userVisibleOnly: true }) + .catch(console.error); + + if (!subscription) { + return; + } + + // the subscription object is what we want to send to our backend + console.log(subscription.endpoint); + } +} +``` + +We should also check our subscription every time our app is accessed, because the subscription object can change. + +```tsx +self.registration.pushManager.getSubscription().then(subscription => { + if (!subscription) { + // ask the user to register for push + return; + } + + // update the database + console.log(subscription); +}); +``` + +### Further Reading + +* For more information on push notifications and the related APIs please refer to the [Web Fundamentals Introduction to Push Notifications](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications) and the [MDN Push API docs](https://developer.mozilla.org/en-US/docs/Web/API/Push_API). +* [This Twitter thread by David Brunelle](https://twitter.com/davidbrunelle/status/1073394572980453376) explains how to implement versioning in your PWA in order to handle breaking API changes. The problem here is that your service worker enabled app will continue to serve an outdated (cached) app against your updated API. In order to solve this a version check can be implemented. diff --git a/versioned_docs/version-v4.20/guides/store.md b/versioned_docs/version-v4.20/guides/store.md new file mode 100644 index 000000000..b293435ab --- /dev/null +++ b/versioned_docs/version-v4.20/guides/store.md @@ -0,0 +1,131 @@ +--- +title: 'Store' +sidebar_label: Stencil Store +description: Store +slug: /stencil-store +--- + +# @stencil/store + +[Store](https://github.com/ionic-team/stencil-store) is a lightweight shared state library by the stencil core team. It implements a simple key/value map that efficiently re-renders components when necessary. + +- Lightweight +- Zero dependencies +- Simple API, like a reactive Map +- Best performance + +## Installation + +```bash npm2yarn +npm install @stencil/store --save-dev +``` + +## Example + +**store.ts:** + +```tsx +import { createStore } from "@stencil/store"; + +const { state, onChange } = createStore({ + clicks: 0, + seconds: 0, + squaredClicks: 0 +}); + +onChange('clicks', value => { + state.squaredClicks = value ** 2; +}); + +export default state; +``` + +**component.tsx:** + +```tsx +import { Component, h } from '@stencil/core'; +import state from '../store'; + +@Component({ + tag: 'app-profile', +}) +export class AppProfile { + + componentWillLoad() { + setInterval(() => state.seconds++, 1000); + } + + render() { + return ( +
    +

    + +

    + Seconds: {state.seconds} +
    + Squared Clicks: {state.squaredClicks} +

    +

    +
    + ); + } +} + +const MyGlobalCounter = () => { + return ( + + ); +}; +``` + +## API + +### `createStore(initialState)` + +Create a new store with the given initial state. The type is inferred from `initialState`, or can be passed as the generic type `T`. + +Returns a `store` object with the following properties. + +### `store.state` + +The state object is proxied, I.E. you can directly get and set properties and Store will automatically take care of component re-rendering when the state object is changed. + +### `store.on(event, listener)` + +Add a listener to the store for a certain action. + +### `store.onChange(propName, listener)` + +Add a listener that is called when a specific property changes. + +### `store.get(propName)` + +Get a property's value from the store. + +### `store.set(propName, value)` + +Set a property's value in the store. + +### `store.reset()` + +Reset the store to its initial state. + +### `store.use(...subscriptions)` + +Use the given subscriptions in the store. A subscription is an object that defines one or more of the properties `get`, `set` or `reset`. + + +## Testing + +Like any global state library, state should be reset between each spec test. +Use the `dispose()` API in the `beforeEach` hook. + +```ts +import store from '../store'; + +beforeEach(() => { + store.dispose(); +}); +``` diff --git a/versioned_docs/version-v4.20/guides/style-guide.md b/versioned_docs/version-v4.20/guides/style-guide.md new file mode 100644 index 000000000..1f18b31d1 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/style-guide.md @@ -0,0 +1,269 @@ +--- +title: Stencil Style Guide +sidebar_label: Style Guide +description: Stencil Style Guide +slug: /style-guide +--- + +# Stencil Style Guide + +This is a component style guide created and enforced internally by the core team of Stencil, for the purpose of standardizing Stencil components. This should only be used as a reference for other teams in creating their own style guides. Feel free to modify to your team's own preference. + +:::note +In order to enforce this (or your team's) style guide, we recommend leveraging a static analysis tool like [ESLint](https://eslint.org/). [@stencil-community/eslint-plugin](https://www.npmjs.com/package/@stencil-community/eslint-plugin) provides rules specifically for writing Stencil components. +::: + +:::note +This guide once recommended TSLint as a static analysis tool. TSLint has been deprecated by its maintaining organization in favor of ESLint and is no longer recommended by the Stencil team. +::: + +## File structure + +- One component per file. +- One component per directory. Though it may make sense to group similar components into the same directory, we've found it's easier to document components when each one has its own directory. +- Implementation (.tsx) and styles of a component should live in the same directory. + +Example from ionic-core: + +```bash +├── my-card +│ ├── my-card.ios.css +│ ├── my-card.md.css +│ ├── my-card.css +│ ├── my-card.tsx +│ └── test +│ └── basic +│ ├── e2e.js +│ └── index.html +├── my-card-content +│ ├── my-card-content.ios.css +│ ├── my-card-content.md.css +│ ├── my-card-content.css +│ └── my-card-content.tsx +├── my-card-title +│ ├── my-card-title.ios.css +│ ├── my-card-title.md.css +│ ├── my-card-title.css +``` + + +## Naming +### HTML tag + +#### Prefix +The prefix has a major role when you are creating a collection of components intended to be used across different projects, like [@ionic/core](https://www.npmjs.com/package/@ionic/core). Web Components are not scoped because they are globally declared within the webpage, which means a "unique" prefix is needed to prevent collisions. The prefix also helps to quickly identify the collection a component is part of. Additionally, web components are required to contain a "-" dash within the tag name, so using the first section to namespace your components is a natural fit. + +We do not recommend using "stencil" as prefix, since Stencil DOES NOT emit stencil components, but rather the output is standards compliant web components. + +DO NOT do this: +```markup + + +``` + +Instead, use your own naming or brand. For example, [Ionic](https://ionicframework.com/) components are all prefixed with `ion-`. +```markup + + +``` + +#### Name + +Components are not actions, they are conceptually "things". It is better to use nouns instead of verbs, such as "animation" instead of "animating". "input", "tab", "nav", "menu" are some examples. + + +#### Modifiers + +When several components are related and/or coupled, it is a good idea to share the name, and then add different modifiers, for example: + +```markup + + + +``` + + +### Component (TS class) + +The name of the ES6 class of the component SHOULD NOT have a prefix since classes are scoped. There is no risk of collision. + +```tsx +@Component({ + tag: 'ion-button' +}) +export class Button { ... } + +@Component({ + tag: 'ion-menu' +}) +export class Menu { ... } +``` + + +## TypeScript + +1. **Use private variables and methods as much possible:** They are useful to detect dead code and enforce encapsulation. Note that this is a feature which TypeScript provides to help harden your code, but using `private`, `public` or `protected` does not make a difference in the actual JavaScript output. + +2. **Code with Method/Prop/Event/Component decorators should have JSDocs:** This allows for documentation generation and for better user experience in an editor that has TypeScript intellisense + +## Code organization + +**Newspaper Metaphor from The Robert C. Martin's _Clean Code_** + +:::note +The source file should be organized like a newspaper article, with the highest level summary at the top, and more and more details further down. Functions called from the top function come directly below it, and so on down to the lowest level and most detailed functions at the bottom. This is a good way to organize the source code, even though IDEs make the location of functions less important, since it is so easy to navigate in and out of them. +::: + +### High level example (commented) + +```tsx +@Component({ + tag: 'ion-something', + styleUrls: { + ios: 'something.ios.css', + md: 'something.md.css', + wp: 'something.wp.css' + } +}) +export class Something { + + /** + * 1. Own Properties + * Always set the type if a default value has not + * been set. If a default value is being set, then type + * is already inferred. List the own properties in + * alphabetical order. Note that because these properties + * do not have the @Prop() decorator, they will not be exposed + * publicly on the host element, but only used internally. + */ + num: number; + someText = 'default'; + + /** + * 2. Reference to host HTML element. + * Inlined decorator + */ + @Element() el: HTMLElement; + + /** + * 3. State() variables + * Inlined decorator, alphabetical order. + */ + @State() isValidated: boolean; + @State() status = 0; + + /** + * 4. Public Property API + * Inlined decorator, alphabetical order. These are + * different than "own properties" in that public props + * are exposed as properties and attributes on the host element. + * Requires JSDocs for public API documentation. + */ + @Prop() content: string; + @Prop() enabled: boolean; + @Prop() menuId: string; + @Prop() type = 'overlay'; + + /** + * Prop lifecycle events SHOULD go just behind the Prop they listen to. + * This makes sense since both statements are strongly connected. + * - If renaming the instance variable name you must also update the name in @Watch() + * - Code is easier to follow and maintain. + */ + @Prop() swipeEnabled = true; + + @Watch('swipeEnabled') + swipeEnabledChanged(newSwipeEnabled: boolean, oldSwipeEnabled: boolean) { + this.updateState(); + } + + /** + * 5. Events section + * Inlined decorator, alphabetical order. + * Requires JSDocs for public API documentation. + */ + @Event() ionClose: EventEmitter; + @Event() ionDrag: EventEmitter; + @Event() ionOpen: EventEmitter; + + /** + * 6. Component lifecycle events + * Ordered by their natural call order, for example + * WillLoad should go before DidLoad. + */ + connectedCallback() {} + disconnectedCallback() {} + componentWillLoad() {} + componentDidLoad() {} + componentShouldUpdate(newVal: any, oldVal: any, propName: string) {} + componentWillUpdate() {} + componentDidUpdate() {} + componentWillRender() {} + componentDidRender() {} + + /** + * 7. Listeners + * It is ok to place them in a different location + * if makes more sense in the context. Recommend + * starting a listener method with "on". + * Always use two lines. + */ + @Listen('click', { enabled: false }) + onClick(ev: UIEvent) { + console.log('hi!') + } + + /** + * 8. Public methods API + * These methods are exposed on the host element. + * Always use two lines. + * Public Methods must be async. + * Requires JSDocs for public API documentation. + */ + @Method() + async open(): Promise { + // ... + return true; + } + + @Method() + async close(): Promise { + // ... + } + + /** + * 9. Local methods + * Internal business logic. These methods cannot be + * called from the host element. + */ + prepareAnimation(): Promise { + // ... + } + + updateState() { + // ... + } + + /** + * 10. render() function + * Always the last public method in the class. + * If private methods present, they are below public methods. + */ + render() { + return ( + + + + ); + } +} +``` diff --git a/versioned_docs/version-v4.20/guides/typed-components.md b/versioned_docs/version-v4.20/guides/typed-components.md new file mode 100644 index 000000000..243efed31 --- /dev/null +++ b/versioned_docs/version-v4.20/guides/typed-components.md @@ -0,0 +1,46 @@ +--- +title: Typed Components +sidebar_label: Typed Components +description: Typed Components +slug: /typed-components +--- + +# Typed Components + +Web Components generated with Stencil come with type declaration files automatically generated by the Stencil compiler. + +In general, TypeScript declarations provide strong guarantees when consuming components: + +- Ensuring that proper values are passed down as properties +- Code autocompletion in modern IDEs such as VSCode +- Events' details +- Signature of components' methods + +These public types are automatically generated by Stencil in `src/component.d.ts`. +This file allows for strong typing in JSX (just like React) and `HTMLElement` interfaces for each component. + +:::tip +It is recommended that this file be checked in with the rest of your code in source control. +::: + +Because Web Components generated by Stencil are just vanilla Web Components, they extend the `HTMLElement` interface. +For each component a type named `HTML{CamelCaseTag}Element` is registered at the global scope. +This means developers DO NOT have to import them explicitly, just like `HTMLElement` or `HTMLScriptElement` are not imported. + +- `ion-button` => `HTMLIonButtonElement` +- `ion-menu-controller` => `HTMLIonMenuControllerElement` + +```tsx +const button: HTMLIonButtonElement = document.queryElement('ion-button'); +button.fill = 'outline'; +``` + +**IMPORTANT**: always use the `HTML{}Element` interfaces in order to hold references to components. + +## Properties + +This section has moved to [Property Types](../components/properties.md#types) + +### Required Properties + +This section has moved to [Required Properties](../components/properties.md#required-properties) diff --git a/versioned_docs/version-v4.20/guides/vs-code-debugging.md b/versioned_docs/version-v4.20/guides/vs-code-debugging.md new file mode 100644 index 000000000..835a3b66a --- /dev/null +++ b/versioned_docs/version-v4.20/guides/vs-code-debugging.md @@ -0,0 +1,126 @@ +--- +title: Debugging With VS Code +sidebar_label: VS Code Debugging +description: How to debug a Stencil component using VS Code +slug: /vs-code-debugging +--- + +# Debugging With VS Code + +VS Code offers a streamlined debugging experience that can be started with a single click when using [launch configurations](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations). + +If you're unfamiliar with using the VS Code debugger in general, please visit the [VS Code debugger documentation](https://code.visualstudio.com/docs/editor/debugging) for a primer. + +## Requirements for Debugging + +In order for a debugger to function, the Stencil project must be configured to generate source maps for the compiled web components back to the source code. As of Stencil v3, source maps are generated by default, but be sure to double-check the project's Stencil config does not disable this behavior. More information regarding source maps in Stencil can be found in the [project configuration documentation](../config/01-overview.md#sourcemap). + +## Debugging Stencil Components In a Web App + +It's a common use case to want to step through a web component's code as it executes in the browser and VS Code makes that process simple. Combining the debugger with Stencil's dev server in watch mode will allow you to debug changes as they're made. + +### Configuring the VS Code Debugger + +To debug Stencil components as they run in a browser (web app), create (or edit) the `.vscode/launch.json` file with the following configuration: + +```json title=".vscode/launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:3333", + "sourceMaps": true, + "sourceMapPathOverrides": { + "*": "${webRoot}/*" + } + } + ] +} +``` + +:::note +If your Stencil project is within a monorepo structure, you may want (or need) to add the `webRoot` option to the above config to point to the Stencil project's directory. For instance, if you have your Stencil project at `/packages/stencil-library`, you would add the following to the config: + +```json +{ + ..., + "webRoot": "${workspaceFolder}/packages/stencil-library", +} +``` + +::: + +This will create a configuration to open a Chrome debugger instance on port 3333 (the default port used by the Stencil dev server). To use this configuration, start a Stencil dev server (running `npm start` in a [Stencil component starter project](https://stenciljs.com/docs/getting-started)) and then run the configuration from the VS Code debugger tab. At this point, any breakpoints set in the component source code will pause browser execution when hit. + +:::note +If your Stencil project is [configured to use a different port](https://stenciljs.com/docs/dev-server#dev-server-config) for the dev server, you will need to update the `url` property in the debugger configuration with the correct port. +::: + +## Debugging Static Site Generation (SSG) + +Static Site Generation, also known as prerendering, executes your components at build time to generate a snapshot of the rendered styles and markup to be efficiently served to search engines and users on first request. + +Since this step runs in a Node.js process instead of a browser, debugging can't be done directly in the browser. However, debugging is straightforward using existing Node.js debugging techniques. + +### Overview + +The `stencil build --prerender` command will first build the hydrate script for a NodeJS environment, then prerender the site using the build. For a production build this is probably ideal. + +However, while debugging you may not need to keep rebuilding the hydrate script, but you only need to debug through the prerendering process. Stencil creates a file in `dist/hydrate` that is used to actually execute your components. + +To only prerender (and avoid rebuilding), you can use the `stencil prerender dist/hydrate/index.js` command, with the path to the script as a flag. + +### Tips for Debugging Prerendering + +By default, prerendering will start by rendering the homepage, find links within the homepage, and continue to crawl the entire site as it finds more links. While debugging, it might be easier to _not_ crawl every URL in the site, but rather have it only prerender one page. To disable crawling, set the prerender config `crawlUrls: false`. + +Next, you can use the `entryUrls` config to provide an array of paths to prerender, rather than starting at the homepage. + +Additionally, console logs that are printed within the runtime are suppressed while prerendering (otherwise the terminal would be overloaded with logs). By setting `runtimeLogging: true`, the runtime console logs will be printed in the terminal. Below is an example setup for prerender debugging: + +```tsx title="prerender.config.ts" +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + crawlUrls: false, + entryUrls: ['/example'], + hydrateOptions: (_url) => { + return { + runtimeLogging: true, + }; + }, +}; +``` + +### Configuring the VS Code Debugger + +To debug the Stencil prerender process, create (or edit) the `launch.json` file with the following configuration: + +```json title="launch.json" +{ + ..., + "configurations": [ + ..., + { + "type": "node", + "request": "launch", + "name": "Prerender", + "args": [ + "${workspaceFolder}/node_modules/@stencil/core/bin/stencil", + "prerender", + "${workspaceFolder}/dist/hydrate/index.js", + "--max-workers=0", + "--config=${workspaceFolder}/stencil.config.ts" + ], + "protocol": "inspector" + } + ] +} +``` + +This creates a new debugging configuration using the script that hydrates the app. We're starting up the `stencil prerender` command, and providing it a path to where +the hydrate script can be found. Next we're using `--max-workers=0` so we do not fork numerous processes to each of your CPUs which will make it difficult to debug. diff --git a/versioned_docs/version-v4.20/guides/workers.md b/versioned_docs/version-v4.20/guides/workers.md new file mode 100644 index 000000000..f3e5385cf --- /dev/null +++ b/versioned_docs/version-v4.20/guides/workers.md @@ -0,0 +1,284 @@ +--- +title: Web Workers +sidebar_label: Web Workers +description: Web Workers +slug: /web-workers +--- + +# Web Workers + +[Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) are a widely supported technology (Chrome, Firefox, Safari and Edge) that allows JavaScript to execute in a different thread, maximizing the usage of multiple CPUs; but most importantly not blocking the **main thread**. + +The **main thread** is where JavaScript runs by default and has access to the `document`, `window` and other DOM APIs. The problem is that long-running JS prevents the browser from running smooth animations (CSS animations, transitions, canvas, svg...), making your site look frozen. That's why if your application needs to run CPU-intensive tasks, Web Workers are a great help. + + +## When to use Web Workers? + +The first thing to understand is when to use a Web Workers, and when *not* to use them since they come with a set of costs and limitations: + +- There is no access to the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction). This means you cannot interact with `document`, `window` or any elements in the page. +- There is no access to any of the `@stencil/core` APIs. For example, you cannot declare and use a component in a Web Worker, for the same reasons there is **no access to the DOM**. +- A Web Worker has its own **isolated state** since each worker has their own memory space. For example, a variable declared on the main thread cannot be directly referenced from a worker. +- There is an overhead when passing data between workers and the main thread. As a general rule, it's best to minimize the amount of data sent to and from the worker and be mindful if the work to send your data takes more time than doing it on the main thread. +- Communication is always **asynchronous**. Luckily Promises and async/await makes this relatively easy, but it's important to understand that communication between threads is always asynchronous. +- You can **only** pass [primitives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Primitive_values) and objects that implement the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). Best way to think of it is any data that can be serialized to JSON is safe to use. + +In short, it's generally a good idea to use workers to move logic that is thread-blocking -- or UI-blocking, preventing users from interacting with the page -- into a Web Worker, such as real-time code syntax highlighting. + +## Best Practices when using Web Workers + +- Use pure and functional algorithms in workers. `(input1, input2) => output`. +- The worker logic itself can be as complex as it has to be, however, the input and output data should stay fairly simple. +- Look for ways to reduce passing data between the main thread and worker thread. +- Class instances cannot be passed as data. Instead, only work with data can be JSON serializable. +- Minimize state within the worker, or better yet, completely avoid maintaining any state (e.g., don't put redux inside a worker). +- The cost of a worker should be easily amortized because it would be doing some CPU-intensive jobs. + + +## How vanilla Web Workers "work"? + +The browser comes with a `Worker` API, that works the following way: + +```tsx +const worker = new Worker('/my-worker.js'); +worker.postMessage(['send message to worker']); +worker.onmessage = (ev) => { + console.log('data from worker', ev.data); +}; +``` + +This API, while powerful, is very low level and makes it tedious to write complex apps, since the event-driven paradigm leads easily to [spaghetti-code](https://en.wikipedia.org/wiki/Spaghetti_code), and quickly misses out on strongly-typed functions and data. + +For further information, check out [this fantastic tutorial](https://www.html5rocks.com/en/tutorials/workers/basics/) by our friends at HTML5Rocks. + +A Web Worker also requires the generation of a separate JavaScript bundle, such as the `my-worker.js` file in the example above. This means you usually need extra build scripts and tooling that transpiles and bundles the worker entry point into another `.js` file. Additionally, the main bundle must be able to reference the worker bundle's file location, which is oftentimes a challenge after transpiling, bundling, minifying, filename hashing and deploying to production servers. + +Fortunately, Stencil can help you solve these two problems: + +- Tooling: Transpiling, bundling, hashing, worker url path referencing +- Communication: Converting event-based communication to Promises, while still maintaining types. + +## Web Workers with Stencil + +As we already mention, Stencil's compiler can help you to use workers in production seamlessly. Any TypeScript file within the `src` directory that ends with `.worker.ts` will automatically use a worker. For example: + +**src/stuff.worker.ts:** + +```tsx + +export const sum = async (a: number, b: number) => { + return a + b; +} + +export const expensiveTask = async (buffer: ArrayBuffer) => { + for (let i = 0; i < buffer.length; i++) { + // do a lot of processing + } + return buffer; +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; + +// Import the worker directly. +// Stencil will automatically create +// a proxy and run the module in a worker. +// IDEs and TypeScript will treat this import +// no differently than any other ESM import. +import { sum, expensiveTask } from '../../stuff.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + async componentWillLoad() { + // sum() will run inside a worker! and the result is a Promise + const result = await sum(1, 2); + console.log(result); // 3 + + // expensiveTask() will not block the main thread, + // because it runs in parallel inside the worker. + // Note that the functions must be async. + const newBuffer = await expensiveTask(buffer); + console.log(newBuffer); + } +} +``` + + +Under the hood, Stencil compiles a worker file and uses the standard `new Worker()` API to instantiate the worker. Then it creates proxies for each of the exported functions, so developers can interact with it using [structured programming constructs](https://en.wikipedia.org/wiki/Structured_programming) instead of event-based ones. + +:::note +Workers are already placed in a different chunk, and dynamically loaded using `new Worker()`. You should avoid using a dynamic `import()` to load them, as this will cause two network requests. Instead, use ES module imports as it's only importing the proxies for communicating with the worker. +::: + +### Imports within a worker + +Normal `ESM` imports are possible when building workers in Stencil. Under the hood, the compiler bundles all the dependencies of a worker into a single file that becomes the worker's entry-point, a dependency-free file that can run without problems. + +**src/loader.worker.ts:** + +```tsx +import upngjs from 'upng-js'; +import { Images } from './materials'; + +export const loadTexture = async (imagesSrcs: Images) => { + const images = await Promise.all( + imagesSrcs.map(loadOriginalImage) + ); + return images; +} + +async function loadOriginalImage(src: string) { + const res = await fetch(src); + const png = upngjs.decode(await res.arrayBuffer()); + return png; +} +``` + +In this example, we are building a worker called `loader.worker.ts` that imports an NPM dependency (`upngjs`, used to parse png files), and a local module (`./materials`). Stencil will use [Rollup](https://rollupjs.org/guide/en/) to bundle all dependencies and remove all imports at runtime. Be aware that code will be duplicated if imported inside and outside a worker. + +#### Dynamic imports + +In order to load scripts dynamically inside of a worker, Web Workers come with a handy API, [`importScript()`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts). + +Here's an example of how to use `typescript` directly from a CDN with `importScript()`. + +```tsx +importScripts("https://cdn.jsdelivr.net/npm/typescript@latest/lib/typescript.js"); +``` + +:::note +Do not use `importScript()` to import NPM dependencies you have installed using `npm` or `yarn`. Use normal ES module imports as usual, so the bundler can understand it. +::: + +### Worker Callbacks + +In most cases, waiting for a Promise to resolve with the output data is all we'll need. However, a limitation with native Promises is that it provides only one returned value. Where a traditional callback still shines is that it can be called numerous times with different data. + +Let's say that we have a long running process that may take a few seconds to complete. With a Promise, we're unable to periodically receive the progress of the task, since all we can do is wait for Promise to resolve. + +A feature with Stencil's worker is the ability to pass a callback to the method, and within the worker, execute the callback as much as it's needed before the task resolves. + +In the example below, the task is given a number that it counts down from the number provided, and the task completes when it gets to `0`. During the count down, however, the main thread will still receive an update every second. This example will console log from `5` to `0` + + +**src/countdown.worker.ts:** + +```tsx +export const countDown = (num: number, progress: (p: number) => void) => { + return new Promise(resolve => { + const tmr = setInterval(() => { + num--; + if (num > 0) { + progress(num); + } else { + clearInterval(tmr); + resolve(num); + } + }, 1000); + }); +}; +``` + +**src/my-app/my-app.tsx:** +```tsx +import { Component } from '@stencil/core'; +import { countDown } from '../countdown.worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + const startNum = 5; + console.log('start', startNum); + + countDown(startNum, (p) => { + console.log('progress', p); + }).then(result => { + console.log('finish', result); + }); + } +} +``` + +When executed, the result would take 5 seconds and would log: + +``` +start 5 +progress 4 +progress 3 +progress 2 +progress 1 +finish 0 +``` + +## Advanced cases + +Sometimes it might be necessary to access the actual [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) instance, because manual usage of the [`postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage) and [`onmessage`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/onmessage) is desired. However, there's still a tooling challenge in having to bundle the worker, and have the main bundle correctly reference the worker bundle url path. In that case, Stencil also has an API that exposes the worker directly so it can be used instead of the proxies mentioned early. + +For a direct worker reference, add `?worker` at the end of an ESM import. This virtual ES module will export: +- `worker`: The actual Worker instance. +- `workerPath`: The path to the worker's entry-point (usually a path to a `.js` file). +- `workerName`: The name of the worker, useful for debugging purposes. + + +**src/my-app/my-app.tsx:** + +```tsx +import { Component } from '@stencil/core'; +import { sum } from '../../stuff.worker'; + +// Using the ?worker query, allows to access the worker instance directly. +import { worker } from '../../stuff.worker.ts?worker'; + +@Component({ + tag: 'my-cmp' +} +export class MyApp { + + componentWillLoad() { + // Use worker api directly + worker.postMessage(['send data manually']); + + // Use the proxy + const result = await sum(1, 2); + console.log(result); // 3 + } +} +``` + +You can even use this feature you create multiple Worker manually: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; + +const workerPool = [ + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), + new Worker(workerPath), +]; +``` + +In this example, we exclusively take advantage of the bundling performed by the compiler to obtain the `workerPath` to the worker's entry point, then manually create a pool of workers. + +:::note +Stencil will not instantiate a worker if it's unused, it takes advantage of tree-shaking to do this. +::: + +#### Worker Termination + +Any Web Workers can be terminated using the [`Worker.terminate()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate) API, but since Stencil creates one worker shared across all the proxied methods, it's not recommended to terminate it manually. If you have a use-case for using `terminate` and rebuilding workers, then we recommend using the `workerPath` and creating a new Worker directly: + +```tsx +import { workerPath } from '../../stuff.worker.ts?worker'; +const worker = new Worker(workerPath); +// ... +worker.terminate() +``` diff --git a/versioned_docs/version-v4.20/introduction/01-overview.md b/versioned_docs/version-v4.20/introduction/01-overview.md new file mode 100644 index 000000000..a05312401 --- /dev/null +++ b/versioned_docs/version-v4.20/introduction/01-overview.md @@ -0,0 +1,48 @@ +--- +title: Stencil - A Compiler for Web Components +sidebar_label: Overview +description: Stencil has a number of add-ons that you can use with the build process. +slug: /introduction +--- + +# Overview + +## Stencil: A Web Components Compiler + +Stencil is a compiler that generates Web Components (more specifically, Custom Elements). Stencil combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil uses TypeScript, JSX, and CSS to create standards-compliant Web Components that can be used to craft high quality component libraries. + +Web Components generated with Stencil can be used with popular frameworks right +out of the box. In addition, Stencil can generate framework-specific wrappers that +allow Stencil components to be used with a framework-specific developer experience. + +Compared with using the [Custom Elements +APIs](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) +directly, Stencil provides [convenient APIs](../components/api.md) which make writing fast +components simpler. With a Virtual DOM, JSX, and async rendering, it is easy to +create fast and powerful components which are still 100% compatible with Web +Components standards. In addition to making it easier to author Custom +Elements, Stencil also adds a number of key capabilities on top of Web +Components, such as prerendering and objects-as-properties (instead of just +strings). + +The developer experience is also tuned, and comes with live reload and a small dev server baked in to the compiler. + +## How can I use Stencil? + +### Design Systems & Component Libraries + +Stencil's primary objective is providing amazing tools for design systems and component libraries. Components as a concept provide similar language for engineers and designers to have productive conversations about design implementation. [Visit the Stencil for Design Systems page to learn more.](../guides/design-systems.md) + +## The History of Stencil + +Stencil was originally created by the **[Ionic Framework](http://ionicframework.com/)** team in order to build faster, more capable components that worked across every major framework. + +The emergence of Progressive Web Apps as a rapidly growing target for web developers demanded a different approach to web app development performance. With Ionic's classic use of traditional frameworks and bundling techniques, the team was struggling to meet latency and code size demands for Progressive Web Apps that ran equally well on fast and slow networks, across a diversity of platforms and devices. + +Additionally, framework fragmentation had created a web development interoperability nightmare, where components built for one framework didn't work with another framework. + +Web Components offered a solution to both problems, pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + +Web Components by themselves, however, weren't enough. Building fast web apps required innovations that were previously locked up inside of traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. While Stencil is intended to be used primarily to build design systems and component libraries, these innovations allowed entire applications to be built using only Stencil. diff --git a/versioned_docs/version-v4.20/introduction/02-goals-and-objectives.md b/versioned_docs/version-v4.20/introduction/02-goals-and-objectives.md new file mode 100644 index 000000000..7538e2a8b --- /dev/null +++ b/versioned_docs/version-v4.20/introduction/02-goals-and-objectives.md @@ -0,0 +1,31 @@ +--- +title: Stencil Goals and Objectives +sidebar_label: Goals and Objectives +description: Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. +slug: /goals-and-objectives +--- + +# Stencil Goals And Objectives + +Stencil aims to combine the best concepts of the most popular frontend frameworks into a compile-time tool rather than run-time tool. It's important to stress that Stencil's goal is to *not* become or be seen as a "framework", but rather our goal is to provide a great developer experience and tooling expected from a framework, while using web-standards within the browser at run-time. In many cases, Stencil can be used as a drop in replacement for traditional frontend frameworks given the capabilities now available in the browser, though using it as such is certainly not required. + +## Web Standards +Components generated by Stencil in the end are built on top of web components, so they work in any major framework or with no framework at all. Additionally, other standards heavily relied on include ES Modules and dynamic imports which have proven to replace traditional bundlers which add unnecessary complexities and run-time JavaScript. By using web-standards, developers can learn and adopt a standard API documented across the world, rather than custom framework APIs that continue to change. + +## Automatic Optimizations +There are countless optimizations and tweaks developers must do to improve performance of components and websites. With a compiler, Stencil is able to analyze component code as an input, and generate optimized components as an output. + +## Future-Friendly +As the world of software development continues to evolve, so too can the compiler. Instead of requiring complete rewrites of components, the compiler can continue to make optimizations using the standard component model as the common input. The compiler allows developers to create future-friendly components, while still staying up-to-date on the latest optimizations without starting over again and again. Additionally, if something changes about any API, the compiler is able to make automatic adjustments and notify the developer exactly what needs to be updated. + +## Run-time Performance +Instead of writing custom client-side JavaScript which every user needs to download and parse for the app to work, Stencil instead prefers to use the already amazing APIs built directly within the browser. These APIs include Custom Elements. + +## Tiny API +Stencil purposely does not come with a large custom API which needs to be learned and re-learned, but rather heavily relies on, you guessed it, web-standards. Again, our goal is to not create yet-another-framework, but rather provide tooling for developers to generate future-friendly components using APIs already baked within the browser. The smaller the API, the easier to learn, and the less that can be broken. + +## Framework Features During Development +If you haven't noticed already we think web-standards are great and offer many benefits. While using web-standards without any structure is certainly possible, and there are actually many use-cases where this would be appropriate, we found that as apps and teams scale it quickly becomes difficult to manage. Developers often gravitate to frameworks because of their great tooling, defined structure, and ability to allow developers to build apps quickly. One of the largest goals of Stencil is to be that intersection of having great framework features and first-class tooling during development but generating future-proof web-standard code, rather than custom framework specific code. + +## Wide Browser Support +For the small minority of browsers that do not support modern browser features and APIs, Stencil will automatically polyfill them on-demand. What this means is that for browsers that already support the feature natively, they will not have to download and parse any unnecessary JavaScript. The great news is that in today's web landscape, most modern APIs are already shipping for what Stencil requires. diff --git a/versioned_docs/version-v4.20/introduction/03-getting-started.md b/versioned_docs/version-v4.20/introduction/03-getting-started.md new file mode 100644 index 000000000..c7a2bb064 --- /dev/null +++ b/versioned_docs/version-v4.20/introduction/03-getting-started.md @@ -0,0 +1,222 @@ +--- +title: Getting Started +sidebar_label: Getting Started +description: Getting Started +slug: /getting-started +--- + +# Getting Started + +## Starting a New Project + +### Prerequisites +Stencil requires a recent LTS version of [NodeJS](https://nodejs.org/) and npm/yarn. +Make sure you've installed and/or updated Node before continuing. + +### Running the `create-stencil` CLI +The `create-stencil` CLI can be used to scaffold a new Stencil project, and can be run using the following command: + +```bash npm2yarn + npm init stencil +``` + +Stencil can be used to create standalone components, or entire apps. +`create-stencil`, will provide a prompt so that you can choose the type of project to start: + +```text +? Select a starter project. + +Starters marked as [community] are developed by the Stencil +Community, rather than Ionic. For more information on the +Stencil Community, please see github.com/stencil-community + +❯ component Collection of web components that can be + used anywhere + app [community] Minimal starter for building a Stencil + app or website + ionic-pwa [community] Ionic PWA starter with tabs layout and routes +``` + +Selecting the 'component' option will prompt you for the name of your project. +Here, we'll name our project 'my-first-stencil-project': + +```bash +✔ Pick a starter › component +? Project name › my-first-stencil-project +``` + +After hitting `ENTER` to confirm your choices, the CLI will scaffold a Stencil project for us in a directory that matches the provided project name. +Upon successfully creating our project, the CLI will print something similar to the following to the console: + +```bash +✔ Project name › my-first-stencil-project +✔ A new git repo was initialized +✔ All setup in 26 ms + + We suggest that you begin by typing: + + $ cd my-first-stencil-project + $ npm install + $ npm start + + $ npm start + Starts the development server. + + $ npm run build + Builds your project in production mode. + + $ npm test + Starts the test runner. + + Further reading: + + - https://github.com/ionic-team/stencil-component-starter + + Happy coding! 🎈 +``` + +The first section describes a few commands required to finish getting your project bootstrapped. + +```bash npm2yarn +cd my-first-stencil-project +npm install +npm start +``` + +This will change your current directory to `my-first-stencil-project`, install your dependencies for you, and start the development server. + +### Useful Initial Commands + +The second section of the `create-stencil` output describes a few useful commands available during the development process: + +- `npm start` starts a local development server. The development server will open a new browser tab containing your +project's components. The dev-server uses hot-module reloading to update your components in the browser as you modify +them for a rapid feedback cycle. + +- `npm run build` creates a production-ready version of your components. The components generated in this step are not +meant to be used in the local development server, but rather within a project that consumes your components. + +- `npm test` runs your project's tests. The `create-stencil` CLI has created both end-to-end and unit tests when scaffolding your project. + +### Source Control + +As of create-stencil v3.3.0, a new git repository will be automatically created for you when you initialize a project if: +1. git is installed +2. Your project is not created under another git work tree (e.g. if you create a new project in a monorepo, a new git repo will not be created) + +Versions of create-stencil prior to v3.3.0 do not interact with any version control systems (VCS). +If you wish to place your project under version control, we recommend initializing your VCS now. +If you wish to use git, run the following after changing your current directory to the root of your Stencil project: + +```bash +$ git init +$ git add -A +$ git commit -m "initialize project using stencil cli" +``` + +## My First Component + +Stencil components are created by adding a new file with a `.tsx` extension, such as `my-component.tsx`. +The `.tsx` extension is required since Stencil components are built using [JSX](../components/templating-and-jsx.md) and TypeScript. + +When we ran `create-stencil` above, it generated a component, `my-component.tsx`, that can be found in the `src/components/my-component` directory: + +```tsx title="my-component.tsx" +import { Component, Prop, h } from '@stencil/core'; +import { format } from '../../utils/utils'; + +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +export class MyComponent { + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; + + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +} +``` + +Once compiled, this component can be used in HTML just like any other tag. + +```markup + +``` + +When rendered, the browser will display `Hello World! I'm Stencil 'Don't call me a framework' JS`. + +### Anatomy of `my-component` + +Let's dive in and describe what's happening in `my-component`, line-by-line. + +After the import statements, the first piece we see is the [`@Component` decorator](../components/component.md): +```tsx +@Component({ + tag: 'my-component', + styleUrl: 'my-component.css', + shadow: true, +}) +``` +This decorator provides metadata about our component to the Stencil compiler. +Information, such as the custom element name (`tag`) to use, can be set here. +This decorator tells Stencil to: +- Set the [element's name](../components/component.md#tag) to 'my-component' +- [Apply the stylesheet](../components/component.md#styleurl) 'my-component.css' to the component +- Enable [native Shadow DOM functionality](../components/component.md#shadow) for this component + +Below the `@Component()` decorator, we have a standard JavaScript class declaration: + +```tsx +export class MyComponent { +``` + +Within this class is where you'll write the bulk of your code to bring your Stencil component to life. + +Next, the component contains three class members, `first`, `middle` and `last`. +Each of these class members have the [`@Prop()` decorator](../components/properties.md#the-prop-decorator-prop) applied to them: +```ts + @Prop() first: string; + @Prop() middle: string; + @Prop() last: string; +``` +`@Prop()` tells Stencil that the property is public to the component, and allows Stencil to rerender when any of these public properties change. +We'll see how this works after discussing the `render()` function. + +In order for the component to render something to the screen, we must declare a [`render()` function](../components/templating-and-jsx.md#basics) that returns JSX. +If you're not sure what JSX is, be sure to reference the [Using JSX](../components/templating-and-jsx.md) docs. + +The quick idea is that our render function needs to return a representation of the HTML we want to push to the DOM. + +```tsx + private getText(): string { + return format(this.first, this.middle, this.last); + } + + render() { + return
    Hello, World! I'm {this.getText()}
    ; + } +``` + +This component's `render()` returns a `
    ` element, containing text to render to the screen. + +The `render()` function uses all three class members decorated with `@Prop()`, through the `getText` function. +Declaring private functions like `getText` helps pull logic out of the `render()` function's JSX. + +Any property decorated with `@Prop()` is also automatically watched for changes. +If a user of our component were to change the element's `first`, `middle`, or `last` properties, our component would fire its `render()` function again, updating the displayed content. + +## Updating Stencil + +To get the latest version of @stencil/core you can run: + +```bash npm2yarn +npm install @stencil/core@latest --save-exact +``` diff --git a/versioned_docs/version-v4.20/introduction/_category_.json b/versioned_docs/version-v4.20/introduction/_category_.json new file mode 100644 index 000000000..fa1c06ac8 --- /dev/null +++ b/versioned_docs/version-v4.20/introduction/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Introduction", + "position": 1 +} diff --git a/versioned_docs/version-v4.20/introduction/upgrading-to-stencil-four.md b/versioned_docs/version-v4.20/introduction/upgrading-to-stencil-four.md new file mode 100644 index 000000000..56b492853 --- /dev/null +++ b/versioned_docs/version-v4.20/introduction/upgrading-to-stencil-four.md @@ -0,0 +1,257 @@ +--- +title: Upgrading to Stencil v4.0.0 +description: Upgrading to Stencil v4.0.0 +url: /docs/upgrading-to-stencil-4 +--- + +# Upgrading to Stencil v4.0.0 + +## Getting Started + +We recommend that you only upgrade to Stencil v4 from Stencil v3. +If you're a few versions behind, we recommend upgrading one major version at a time (from v1 to v2, then v2 to v3, finally v3 to v4). +This will minimize the number of breaking changes you have to deal with at the same time. + +For breaking changes introduced in previous major versions of the library, see: +- [Stencil v3 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v300) +- [Stencil v2 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-two) +- [Stencil v1 Breaking Changes](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-one) + +For projects that are on Stencil v3, install the latest version of Stencil v4: `npm install @stencil/core@4` + + +## Updating Your Code + +### New Configuration Defaults +Starting with Stencil v4.0.0, the default configuration values have changed for a few configuration options. +The following sections lay out the configuration options that have changed, their new default values, and ways to opt-out of the new behavior (if applicable). + +#### `transformAliasedImportPaths` + +TypeScript projects have the ability to specify a path aliases via the [`paths` configuration in their `tsconfig.json`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) like so: +```json title="tsconfig.json" +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@utils": ["src/utils/index.ts"] + } + } +} +``` +In the example above, `"@utils"` would be mapped to the string `"src/utils/index.ts"` when TypeScript performs type resolution. +The TypeScript compiler does not however, transform these paths from their keys to their values as a part of its output. +Instead, it relies on a bundler/loader to do the transformation. + +The ability to transform path aliases was introduced in [Stencil v3.1.0](https://github.com/ionic-team/stencil/releases/tag/v3.1.0) as an opt-in feature. +Previously, users had to explicitly enable this functionality in their `stencil.config.ts` file with `transformAliasedImportPaths`: +```ts title="stencil.config.ts - enabling 'transformAliasedImportPaths' in Stencil v3.1.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: true, + // ... +}; +``` + +Starting with Stencil v4.0.0, this feature is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v3.1.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPaths' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + transformAliasedImportPaths: false, + // ... +}; +``` + +For more information on this flag, please see the [configuration documentation](../config/01-overview.md#transformaliasedimportpaths) + +#### `transformAliasedImportPathsInCollection` + +Introduced in [Stencil v2.18.0](https://github.com/ionic-team/stencil/releases/tag/v2.18.0), `transformAliasedImportPathsInCollection` is a configuration flag on the [`dist` output target](../output-targets/dist.md#transformaliasedimportpathsincollection). +`transformAliasedImportPathsInCollection` transforms import paths, similar to [`transformAliasedImportPaths`](#transformaliasedimportpaths). +This flag however, only enables the functionality of `transformAliasedImportPaths` for collection output targets. + +Starting with Stencil v4.0.0, this flag is enabled by default. +Projects that had previously enabled this functionality that are migrating from Stencil v2.18.0+ may safely remove the flag from their Stencil configuration file(s). + +For users that run into issues with this new default, we encourage you to file a [new issue on the Stencil GitHub repo](https://github.com/ionic-team/stencil/issues/new?assignees=&labels=&projects=&template=bug_report.yml&title=bug%3A+). +As a workaround, this flag can be set to `false` to disable the default functionality. +```ts title="stencil.config.ts - disabling 'transformAliasedImportPathsInCollection' in Stencil v4.0.0" +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist', + transformAliasedImportPathsInCollection: false, + }, + // ... + ] + // ... +}; +``` + +For more information on this flag, please see the [`dist` output target's documentation](../output-targets/dist.md#transformaliasedimportpathsincollection). + +### In Browser Compilation Support Removed + +Prior to Stencil v4.0.0, components could be compiled from TSX to JS in the browser. +This feature was seldom used, and has been removed from Stencil. +At this time, there is no replacement functionality. +For additional details, please see the [request-for-comment](https://github.com/ionic-team/stencil/discussions/4134) on the Stencil GitHub Discussions page. + +### Legacy Context and Connect APIs Removed + +Previously, Stencil supported `context` and `connect` as options within the `@Prop` decorator. +Both of these APIs were deprecated in Stencil v1 and are now removed. + +```ts +@Prop({ context: 'config' }) config: Config; +@Prop({ connect: 'ion-menu-controller' }) lazyMenuCtrl: Lazy; +``` +To migrate away from usages of `context`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propcontext). +To migrate away from usages of `connect`, please see [the original deprecation announcement](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#propconnect). + +### Legacy Browser Support Removed + +In Stencil v3.0.0, we announced [the deprecation of IE 11, pre-Chromium Edge, and Safari 10 support](https://github.com/ionic-team/stencil/blob/1a8ff39073a88d1372beaa98434dbe2247f68a85/BREAKING_CHANGES.md?plain=1#L78). +In Stencil v4.0.0, support for these browsers has been dropped (for a full list of supported browsers, please see our [Browser Support policy](../reference/support-policy.md#browser-support)). + +By dropping these browsers, a few configuration options are no longer valid in a Stencil configuration file: + +#### `__deprecated__cssVarsShim` + +The `extras.__deprecated__cssVarsShim` option caused Stencil to include a polyfill for [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/--*). +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__dynamicImportShim` + +The `extras.__deprecated__dynamicImportShim` option caused Stencil to include a polyfill for +the [dynamic `import()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) +for use at runtime. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__safari10` + +The `extras.__deprecated__safari10` option would patch ES module support for Safari 10. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +#### `__deprecated__shadowDomShim` + +The `extras.__deprecated__shadowDomShim` option would check whether a shim for [shadow +DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) +was needed in the current browser, and include one if so. +This field should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Legacy Cache Stats Config Flag Removed + +The `enableCacheStats` flag was used in legacy behavior for caching, but has not been used for some time. This +flag has been removed from Stencil's API and should be removed from a project's Stencil configuration file (`stencil.config.ts`). + +### Drop Node 14 Support + +Stencil no longer supports Node 14. +Please upgrade local development machines, continuous integration pipelines, etc. to use Node v16 or higher. +For the full list of supported runtimes, please see [our Support Policy](../reference/support-policy.md#javascript-runtime). + +## Information Included in `docs-json` Expanded + +For Stencil v4 the information included in the output of the `docs-json` output +target was expanded to include more information about the types of properties +and methods on Stencil components. + +For more context on this change, see the [documentation for the new `supplementalPublicTypes`](../documentation-generation/docs-json.md#supplementalpublictypes) +option for the JSON documentation output target. + +### `JsonDocsEvent` + +The JSON-formatted documentation for an `@Event` now includes a field called +`complexType` which includes more information about the types referenced in the +type declarations for that property. + +Here's an example of what this looks like for the [ionBreakpointDidChange +event](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/modal/modal.tsx#L289-L292) +on the `Modal` component in Ionic Framework: + +```json +{ + "complexType": { + "original": "ModalBreakpointChangeEventDetail", + "resolved": "ModalBreakpointChangeEventDetail", + "references": { + "ModalBreakpointChangeEventDetail": { + "location": "import", + "path": "./modal-interface", + "id": "src/components/modal/modal.tsx::ModalBreakpointChangeEventDetail" + } + } + } +} +``` + +### `JsonDocsMethod` + +The JSON-formatted documentation for a `@Method` now includes a field called +`complexType` which includes more information about the types referenced in +the type declarations for that property. + +Here's an example of what this looks like for the [open +method](https://github.com/ionic-team/ionic-framework/blob/1f0c8049a339e3a77c468ddba243041d08ead0be/core/src/components/select/select.tsx#L261-L313) +on the `Select` component in Ionic Framework: + +```json +{ + "complexType": { + "signature": "(event?: UIEvent) => Promise", + "parameters": [ + { + "tags": [ + { + "name": "param", + "text": "event The user interface event that called the open." + } + ], + "text": "The user interface event that called the open." + } + ], + "references": { + "Promise": { + "location": "global", + "id": "global::Promise" + }, + "UIEvent": { + "location": "global", + "id": "global::UIEvent" + }, + "HTMLElement": { + "location": "global", + "id": "global::HTMLElement" + } + }, + "return": "Promise" + } +} +``` + +## Additional Packages + +To ensure the proper functioning of other `@stencil/` packages, it is advisable for projects utilizing any of the packages mentioned below to upgrade to the minimum package version specified. + +| Package | Minimum Package Version | GitHub | Documentation | +|----------------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|-------------------------------------------------------------| +| `@stencil/angular-output-target` | [0.7.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fangular-output-target%400.7.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/angular.md) | +| `@stencil/sass` | [3.0.4](https://github.com/ionic-team/stencil-sass/releases/tag/v3.0.4) | [GitHub](https://github.com/ionic-team/stencil-sass) | [GitHub README](https://github.com/ionic-team/stencil-sass) | +| `@stencil/store` | [2.0.8](https://github.com/ionic-team/stencil-store/releases/tag/v2.0.8) | [GitHub](https://github.com/ionic-team/stencil-store) | [Stencil Doc Site](../guides/store.md) | +| `@stencil/react-output-target` | [0.5.1](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Freact-output-target%400.5.1) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/react.md) | +| `@stencil/vue-output-target` | [0.8.6](https://github.com/ionic-team/stencil-ds-output-targets/releases/tag/%40stencil%2Fvue-output-target%400.8.6) | [GitHub](https://github.com/ionic-team/stencil-ds-output-targets) | [Stencil Doc Site](../framework-integration/vue.md) | + +## Need Help Upgrading? + +Be sure to look at the Stencil [v4.0.0 Breaking Changes Guide](https://github.com/ionic-team/stencil/blob/main/BREAKING_CHANGES.md#stencil-v400). + +If you need help upgrading, please post a thread on the [Stencil Discord](https://chat.stenciljs.com). diff --git a/versioned_docs/version-v4.20/output-targets/01-overview.md b/versioned_docs/version-v4.20/output-targets/01-overview.md new file mode 100644 index 000000000..550880879 --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/01-overview.md @@ -0,0 +1,68 @@ +--- +title: Stencil Output Targets +sidebar_label: Overview +description: Stencil Output Targets +slug: /output-targets +--- + +# Output Targets + +One of the more powerful features of the compiler is its ability to generate various builds depending on _"how"_ the components are going to be used. Stencil is able to take an app's source and compile it to numerous targets, such as a webapp to be deployed on an http server, as a third-party component lazy-loaded library to be distributed on [npm](https://www.npmjs.com/), or a vanilla custom elements bundle. By default, Stencil apps have an output target type of `www`, which is best suited for a webapp. + + +## Output Target Types: + - [`dist`: Distribution](./dist.md) + - [`www`: Website](./www.md) + - [`dist-custom-elements`: Custom Elements](./custom-elements.md) + +## Example: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist' + }, + { + type: 'www' + } + ] +}; +``` + +## Primary Package Output Target Validation + +If `validatePrimaryPackageOutputTarget: true` is set in your project's [Stencil config](../config/01-overview.md#validateprimarypackageoutputtarget) Stencil will +attempt to validate certain fields in your `package.json` that correspond with the generated distribution code. Because Stencil can output many different formats +from a single project, it can only validate that the `package.json` has field values that align with one of the specified output targets in your project's config. +So, Stencil allows you to designate which output target should be used for this validation and thus which will be the default distribution when bundling your +project. + +This behavior only affects a small subset of output targets so a flag exists on the following targets that are eligible for this level of validation: `dist`, `dist-types`, +`dist-collection`, and `dist-custom-elements`. For any of these output targets, you can configure the target to be validated as follows: + +```ts title='stencil.config.ts' +import { Config } from '@stencil/core'; + +export const config: Config = { + ..., + outputTargets: [ + { + type: 'dist', + // This flag is what tells Stencil to use this target for validation + isPrimaryPackageOutputTarget: true, + ... + }, + ... + ], + // If this is not set, Stencil will not validate any targets + validatePrimaryPackageOutputTarget: true, +}; +``` + +:::note +Stencil can only validate one of these output targets for your build. If multiple output targets are marked for validation, Stencil will use +the first designated target in the array and ignore all others. +::: diff --git a/versioned_docs/version-v4.20/output-targets/_category_.json b/versioned_docs/version-v4.20/output-targets/_category_.json new file mode 100644 index 000000000..ae7d15137 --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Output Targets", + "position": 6 +} diff --git a/versioned_docs/version-v4.20/output-targets/copy-tasks.md b/versioned_docs/version-v4.20/output-targets/copy-tasks.md new file mode 100644 index 000000000..0b3340791 --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/copy-tasks.md @@ -0,0 +1,97 @@ +--- +title: Stencil Copy Tasks +sidebar_label: Copy Tasks +description: Stencil Copy Tasks +slug: /copy-tasks +--- + + +# Copy Tasks for Output Targets + +All of Stencil's non-documentation output targets +([`dist-custom-elements`](./custom-elements.md), [`dist`](./dist.md), and +[`www`](./www.md)) support a `copy` config which allows you to define file copy +operations which Stencil will automatically perform as part of the build. This +could be useful if, for instance, you had some static assets like images which +should be distributed alongside your components. + +The `copy` attribute on these output targets expects an array of objects corresponding to the following `CopyTask` interface: + +```ts reference title="CopyTask" +https://github.com/ionic-team/stencil/blob/6ed2d4e285544945949ad8e4802fe7f70e392636/src/declarations/stencil-public-compiler.ts#L1594-L1665 +``` + +## Examples + +### Images in the `www` Output Target + +The `copy` config within the following [`www` output target](./www.md) config +will cause Stencil to copy the entire directory from `src/images` to +`www/images`: + +```tsx + outputTargets: [ + { + type: 'www', + copy: [ + { src: 'images' } + ] + } + ] +``` + +In this example, since the `srcDir` property is not set, the default source +directory is `src/`, and since `dest` is not set the contents of `src/images` +will be copied to a new `images` directory in `www`, the default destination +directory for the `www` Output Target. + + +### Setting the `dest` option + +The `dest` property can also be optionally set on a `CopyTask` to either an +absolute path or a path relative to the build directory of the output target. + +In this example we've customized the build directory to be `public` instead of +the default (`'www'`), which, in combination with `dest: 'static/web-fonts'` +will copy the contents of `src/files/fonts` over to `public/static/web-fonts`: + +```tsx + outputTargets: [ + { + type: 'www', + dir: 'public', + copy: [ + { src: 'files/fonts', dest: 'static/web-fonts' } + ] + } + ] +``` + +:::note +When `dest` is set on a `CopyTask` Stencil will, by default, copy all the contents +of the `src` directory to the `dest` directory without creating a new +subdirectory for the contents of `src`. The `keepDirStructure` option can +control this behavior. If it's set to `true` Stencil will always create a +new subdirectory within `dest` with the same name as the `src` directory. In the +above example this would result in the contents of `src/files/fonts` being copied +to `public/static/web-fonts/fonts` instead of `public/static/web-fonts`. + +See the above documentation for the `keepDirStructure` option for more details. +::: + +### Opting-in to warnings + +By default, Stencil will not log a warning if a file or directory specified in +`src` cannot be located. To opt-in to warnings if a copy task source cannot be +found, set `warn: true` in the `CopyTask` object, like so: + +```tsx + outputTargets: [ + { + type: 'dist', + copy: [ + { src: 'fonts', warn: true } + ] + } + ] +``` diff --git a/versioned_docs/version-v4.20/output-targets/custom-elements.md b/versioned_docs/version-v4.20/output-targets/custom-elements.md new file mode 100644 index 000000000..b6fed7bbe --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/custom-elements.md @@ -0,0 +1,236 @@ +--- +title: Custom Elements with Stencil +sidebar_label: dist-custom-elements +description: Custom Elements with Stencil +slug: /custom-elements +--- + +# Custom Elements + +The `dist-custom-elements` output target creates custom elements that directly extend `HTMLElement` and provides simple utility functions for easily defining these elements on the [Custom Element Registry](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry). This output target excels in use in frontend frameworks and projects that will handle bundling, lazy-loading, and custom element registration themselves. + +This target can be used outside of frameworks as well, if lazy-loading functionality is not required or desired. For using lazily loaded Stencil components, please refer to the [dist output target](./dist.md). + +To generate components using the `dist-custom-elements` output target, add it to a project's `stencil.config.ts` file like so: + +```tsx title="stencil.config.ts" +import { Config } from '@stencil/core'; + +export const config: Config = { + // Other top-level config options here + outputTargets: [ + { + type: 'dist-custom-elements', + // Output target config options here + }, + // Other output targets here + ], +}; +``` + +## Config + +### copy + +_default: `undefined`_ + +An array of [copy tasks](./copy-tasks.md) to be executed during the build process. + +### customElementsExportBehavior + +_default: `'default'`_ + +By default, the `dist-custom-elements` output target generates a single file per component, and exports each of those files individually. + +In some cases, library authors may want to change this behavior, for instance to automatically define component children, provide a single file containing all component exports, etc. + +This config option provides additional behaviors that will alter the default component export _OR_ custom element definition behaviors +for this target. The desired behavior can be set via the following in a project's Stencil config: + +```ts +// stencil.config.ts +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'dist-custom-elements', + customElementsExportBehavior: 'default' | 'auto-define-custom-elements' | 'bundle' | 'single-export-module', + }, + // ... + ], + // ... +}; +``` + +| Option | Description | +| ----------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `default` | No additional re-export or auto-definition behavior will be performed.

    This value will be used if no explicit value is set in the config, or if a given value is not a valid option. | +| `auto-define-custom-elements` | A component and its children will be automatically defined with the `CustomElementRegistry` when the component's module is imported. | +| `bundle` | A utility `defineCustomElements()` function is exported from the `index.js` file of the output directory. This function can be used to quickly define all Stencil components in a project on the custom elements registry. | +| `single-export-module` | All component and custom element definition helper functions will be exported from the `index.js` file in the output directory. This file can be used as the root module when distributing your component library, see [Publishing](/publishing) for more details. | + +:::note +At this time, components that do not use JSX cannot be automatically +defined. This is a known limitation of Stencil that users should be aware of. +::: + +### dir + +_default: `'dist/components'`_ + +This config option allows you to change the output directory where the compiled output for this output target will be written. + +### empty + +_default: `true`_ + +Setting this flag to `true` will remove the contents of the [output directory](#dir) between builds. + +### externalRuntime + +_default: `true`_ + +Setting this flag to `true` results in the following behaviors: + +1. Minification will follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). +2. Filenames will not be hashed. +3. All imports from packages under `@stencil/core/*` will be marked as external and therefore not included in the generated Rollup bundle. + +Ensure that `@stencil/core` is included in your list of dependencies if you set this option to `true`. This is crucial to prevent any runtime errors. + +### generateTypeDeclarations + +_default: `true`_ + +By default, Stencil will generate type declaration files (`.d.ts` files) as a part of the `dist-custom-elements` output target through the `generateTypeDeclarations` field on the target options. Type declaration files will be placed in the `dist/types` directory in the root of a Stencil project. At this time, this output destination is not able to be configured. + +Setting this flag to `false` will not generate type declaration files for the `dist-custom-elements` output target. + +:::note +When set to generate type declarations, Stencil respects the export behavior selected via `customElementsExportBehavior` and generates type declarations specific to the content of the generated [output directory's](#dir) `index.js` file. +::: + +### includeGlobalScripts + +_default: `false`_ + +Setting this flag to `true` will include [global scripts](../config/01-overview.md#globalscript) in the bundle and execute them once the bundle entry point in loaded. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### minify + +_default: `false`_ + +Setting this flag to `true` will cause file minification to follow what is specified in the [Stencil config](../config/01-overview.md#minifyjs). _However_, if [`externalRuntime`](#externalruntime) is enabled, it will override this option and always result in minification being disabled. + +## Making Assets Available + +For performance reasons, the generated bundle does not include [local assets](../guides/assets.md) built within the JavaScript output, +but instead it's recommended to keep static assets as external files. By keeping them external this ensures they can be requested on-demand, rather +than either welding their content into the JS file, or adding many URLs for the bundler to add to the output. +One method to ensure [assets](../guides/assets.md) are available to external builds and http servers is to set the asset path using `setAssetPath()`. + +The `setAssetPath()` function is used to manually set the base path where static assets can be found. +For the lazy-loaded output target the asset path is automatically set and assets copied to the correct +build directory. However, for custom elements builds, the `setAssetPath(path)` should be +used to customize the asset path depending on where they are found on the http server. + +If the component's script is a `type="module"`, it's recommended to use `import.meta.url`, such +as `setAssetPath(import.meta.url)`. Other options include `setAssetPath(document.currentScript.src)`, or using a bundler's replace plugin to +dynamically set the path at build time, such as `setAssetPath(process.env.ASSET_PATH)`. + +```tsx +import { setAssetPath } from 'my-library/dist/components'; + +setAssetPath(document.currentScript.src); +``` + +Make sure to copy the assets over to a public directory in your app. This configuration depends on how your script is bundled, or lack of +bundling, and where your assets can be loaded from. How the files are copied to the production build directory depends on the bundler or tooling. +The configs below provide examples of how to do this automatically with popular bundlers. + +## Example Bundler Configs + +Instructions for consuming the custom elements bundle vary depending on the bundler you're using. These examples will help your users consume your components with webpack and Rollup. + +The following examples assume your component library is published to NPM as `my-library`. You should change this to the name you actually publish your library with. + +Users will need to install your library before importing them. + +```bash npm2yarn +npm install my-library +``` + +### webpack.config.js + +A webpack config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `CopyPlugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +const path = require('path'); +const CopyPlugin = require('copy-webpack-plugin'); + +module.exports = { + entry: './src/index.js', + output: { + filename: 'main.js', + path: path.resolve(__dirname, 'dist'), + }, + module: { + rules: [ + { + test: /\.css$/i, + use: ['style-loader', 'css-loader'], + }, + ], + }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + to: path.resolve(__dirname, 'dist/assets'), + }, + ], + }), + ], +}; +``` + +### rollup.config.js + +A Rollup config will look something like the one below. Note how assets are copied from the library's `node_module` folder to `dist/assets` via the `rollup-copy-plugin` utility. This is important if your library includes [local assets](../guides/assets.md). + +```js +import path from 'path'; +import commonjs from '@rollup/plugin-commonjs'; +import copy from 'rollup-plugin-copy'; +import postcss from 'rollup-plugin-postcss'; +import resolve from '@rollup/plugin-node-resolve'; + +export default { + input: 'src/index.js', + output: [{ dir: path.resolve('dist/'), format: 'es' }], + plugins: [ + resolve(), + commonjs(), + postcss({ + extensions: ['.css'], + }), + copy({ + targets: [ + { + src: path.resolve(__dirname, 'node_modules/my-library/dist/my-library/assets'), + dest: path.resolve(__dirname, 'dist'), + }, + ], + }), + ], +}; +``` diff --git a/versioned_docs/version-v4.20/output-targets/dist.md b/versioned_docs/version-v4.20/output-targets/dist.md new file mode 100644 index 000000000..5c33af5d2 --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/dist.md @@ -0,0 +1,106 @@ +--- +title: Distributing Web Components Built with Stencil +sidebar_label: dist +description: Distributing Web Components Built with Stencil +slug: /distribution +--- + +# Distribution Output Target + +The `dist` type is to generate the component(s) as a reusable library that can be self-lazy loading, such as [Ionic](https://www.npmjs.com/package/@ionic/core). When creating a distribution, the project's `package.json` will also have to be updated. However, the generated bundle is tree-shakable, ensuring that only imported components will end up in the build. + +```tsx +outputTargets: [ + { + type: 'dist' + } +] +``` + +## Config + +### collectionDir + +The `collectionDir` config specifies the output directory within the [distribution directory](#dir) where the transpiled output of Stencil components will be written. + +This option defaults to `collection` when omitted from a Stencil configuration file. + +### dir + +The `dir` config specifies the public distribution directory. This directory is commonly the `dist` directory found within [npm packages](https://docs.npmjs.com/getting-started/packages). This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended that this directory not be committed to a repository. + +This option defaults to `dist` when omitted from a Stencil configuration file. + +### empty + +By default, before each build the `dir` directory will be emptied of all files. To prevent this directory from being emptied, change this value to `false`. + +This flag defaults to `true` when omitted from a Stencil configuration file. + +### isPrimaryPackageOutputTarget + +_default: `false`_ + +If `true`, this output target will be used to validate `package.json` fields for your project's distribution. See the overview of [primary package output target validation](./01-overview.md#primary-package-output-target-validation) +for more information. + +### transformAliasedImportPathsInCollection + +*default: `true`* + +This option will allow [path aliases](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in a project's `tsconfig.json` to be transformed into relative paths in the code output under the [collectionDir](#collectiondir) subdirectory for this output target. This does not affect imports for external packages. + +An example of path transformation could look something like: + +```ts +// Source code +import * as utils from '@utils'; + +// Output code +import * as utils from '../path/to/utils'; +``` + +:::tip +If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config. +::: + +### esmLoaderPath + +*default: `/dist/loader`* + +Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading. Read more about the loader directory in the [section below](#loader). + +If you don't use a custom [exports](https://nodejs.org/api/packages.html#exports) map, users would have to import the loader script via: + +```js +import { defineCustomElements } from 'stencil-library/dist/loader' +``` + +By setting `esmLoaderPath` to e.g. `../loader` you can shorten or rename the import path to: + +```js +import { defineCustomElements } from 'stencil-library/loader' +``` + +## Publishing + +Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md). + +## Loader + +The `dist` output target generates a loader directory that exports `setNonce`, `applyPolyfills` and `defineCustomElements` helper functions when imported within an ESM context. This allows you to register all components of your library to be used in your project in an application setup script, e.g.: + +```ts +import { applyPolyfills, defineCustomElements, setNonce } from 'stencil-library/loader'; + +// Will set the `nonce` attribute for all scripts/style tags +// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m') +// Obviously, you should use the nonce generated by your server +setNonce('r4nd0m'); + +applyPolyfills().then(() => { + defineCustomElements(); +}); +``` + +This is an alternative approach to e.g. loading the components directly through a script tag as mentioned below. Read more about `setNonce` and when to set it in our guide on [Content Security Policy Nonces](../guides/csp-nonce.md). diff --git a/versioned_docs/version-v4.20/output-targets/www.md b/versioned_docs/version-v4.20/output-targets/www.md new file mode 100644 index 000000000..6c3079364 --- /dev/null +++ b/versioned_docs/version-v4.20/output-targets/www.md @@ -0,0 +1,32 @@ +--- +title: Webapp Output Target +sidebar_label: www +description: Webapp Output Target +slug: /www +--- + +# Webapp Output Target: `www` + +The `www` output target type is oriented for webapps and websites, hosted from an http server, which can benefit from prerendering and service workers, such as this very site you're reading. If the `outputTarget` config is not provided it'll default to having just the `www` type. + +Even if a project is meant to only build a reusable component library, the `www` output target is useful to build out and test the components throughout development. + +```tsx +outputTargets: [ + { + type: 'www' + } +] +``` + +## Config + +| Property | Description | Default | +|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| +| `baseUrl` | The `baseUrl` represents the site's "base" url to be served from. For example, this site's base url is `https://stenciljs.com/`. However, if the entire site's output is to live within a sub directory, then this directory's path should be the `baseUrl`. For example, Ionic's documentation is a stand-alone Stencil site that lives in the `/docs` directory within `https://ionicframework.com/`. In this example, `https://ionicframework.com/docs/` would be the base url. | `/` | +| `buildDir` | The `buildDir` is the directory of Stencil's generated scripts, such as the component files. For production builds, this directory will contain both `es5` and `esm` builds for each component. (Don't worry, users only request the one their browser needs.) | `build` | +| `dir` | The `dir` config specifies the public web distribution directory. This directory is commonly the root directory of an app to be served, such as serving static files from. This directory is built and rebuilt directly from the source files. Additionally, since this is a build target, all files will be deleted and rebuilt after each build, so it's best to always copy source files into this directory. It's recommended this directory is not committed to a repository. | `www` | +| `empty` | By default, before each build the `dir` directory will be emptied of all files. However, to prevent this directory from being emptied change this value to `false`. | `true` | +| `indexHtml` | The `indexHtml` property represents the location of the root index html file. | `index.html` | +| `serviceWorker` | The `serviceWorker` config lets you customize the service worker that gets automatically generated by the Stencil compiler. To override Stencil's defaults, set any of the values listed in the [Workbox documentation](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). + diff --git a/versioned_docs/version-v4.20/reference/_category_.json b/versioned_docs/version-v4.20/reference/_category_.json new file mode 100644 index 000000000..75879876e --- /dev/null +++ b/versioned_docs/version-v4.20/reference/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Reference", + "position": 10 +} diff --git a/versioned_docs/version-v4.20/reference/faq.md b/versioned_docs/version-v4.20/reference/faq.md new file mode 100644 index 000000000..eab0321a9 --- /dev/null +++ b/versioned_docs/version-v4.20/reference/faq.md @@ -0,0 +1,192 @@ +--- +title: Stencil Frequently Asked Questions +sidebar_label: FAQ +description: Stencil is a developer-focused toolchain for building reusable, scalable component libraries. +slug: /faq +--- + +# FAQ + +## Introduction + +### What is Stencil? + +Stencil is a developer-focused toolchain for building reusable, scalable component libraries. It provides a compiler that generates highly optimized Web Components, and combines the best concepts of the most popular frameworks into a simple build-time tool. + +Stencil focuses on building components with web standards. It’s used by developers and organizations around the world, and is [100% free and MIT open source](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### What does Stencil do? + +Stencil helps developers and teams build and share custom components. Since Stencil generates standards-compliant Web Components, the components you build with Stencil will work with many popular frameworks right out of the box, and can even be used without a framework because they are just Web Components. Stencil also enables a number of key capabilities on top of Web Components, in particular, prerendering, and objects-as-properties (instead of just strings). + + +### Who is Stencil for? + +Stencil is for developers and teams that want to build custom component libraries that can be shared across teams, frameworks and large organizations. + +Stencil can also be used by designers who want their original design visions delivered consistently, with high fidelity, to all users. + + +### Who makes Stencil? + +Stencil is an open source project started by the [Ionic core team](https://ionicframework.com/), with contributions also coming from the community. + + +### Why was Stencil created? + +Stencil was created by the Ionic Framework team to make our own component library faster, smaller, and compatible with all major frameworks. Web Components offered a solution by pushing more work to the browser for better performance, and targeting a standards-based component model that all frameworks could use. + + +### Who uses Stencil? + +Stencil was initially developed for Ionic Framework which is a very successful Web Component-based library & UI framework. Web Components are now in thousands of app store apps, and nearly 4 million new Ionic Framework projects are being created every year. + + +### How does Stencil compare to traditional frameworks? + +The Web Component ecosystem has a diverse set of players, each with a different long-term vision for what Web Components can and should do. + +Some think Web Components should replace third-party app frameworks, while others think that Web Components are more suited for leaf/style/design nodes and shouldn’t get in the business of your app’s component system. There are also many framework developers that don’t see the point of Web Components, or consider them to be an affront to front-end innovation. + +With Stencil, our vision is somewhere in the middle. In the long term, we see app development teams continuing to use their framework of choice. We envision these frameworks continuing to get better, smaller, and more efficient, with increasingly good support for targeting and consuming Web Components -- and big teams will be consuming an increasing amount of Web Components as companies continue to embrace them for shared component libraries. + +At the same time, we believe an indispensable feature for Web Components is solving those component distribution and design system problems. We also believe, however, that 90% of the market doesn’t have those problems to begin with, so the current debate about the merits of Web Components is somewhat unproductive. + + +### Why is Stencil considered framework-agnostic? + +Perhaps the most appealing benefit of Web Components is that they give your development teams the flexibility to choose the underlying tools and frameworks - and versions of those frameworks - and tools that they prefer. As pointed out earlier, one of the great challenges of implementing a universal set of components is getting all of your development teams to standardize on just one set of technologies. With Web Components, each team can use what works best for them, giving them complete freedom to use the tools they love—today and tomorrow. + + +## What does Stencil provide? + +### Does Stencil have a component library? + +The most widely used Stencil component library is the Ionic Framework, however, Stencil itself is only a toolchain and does not provide its own component library. We encourage you to first review Ionic components if you are building an application. + + +### Is Stencil a framework? + +Stencil purposely does not strive to act as a stand-alone framework, but rather a tool which allows developers to scale framework-agnostic components across many projects, teams and large organizations. One of Stencil’s superpowers is its flexibility: its components could be used stand-alone, or within traditional frameworks. + + +### Does Stencil come with a testing framework? + +Yes, Stencil provides a rich set of APIs for unit and End-to-end tests. [Learn more about testing with Stencil](../testing/01-overview.md). + + + +## Technology + + +### Why does Stencil use web components? + +By using a consistent set of web standards, Web Components do not depend on a specific framework runtime to execute. As frameworks change their APIs, Web Components do not, allowing for the original source to continue to work natively in a browser. + + +### How is Stencil able to optimize component file size and startup? + +Traditional frameworks provide a runtime API, and developers can pick and choose which APIs to use per component. However, this means every feature needs to be available to every component, just in case the component may or may not use the API. + +With Stencil, the compiler is able to perform static analysis on each component in order to understand which APIs are and are not being used. By doing so, Stencil is able to customize each build to use exactly what each component needs, making for a highly optimized runtime with minimal size. + +Since Stencil uses a compiler, it is able to adjust code as new improvements and features become available. Source code can continue to be written using the same public API and syntax, while the compiler can adjust the code to further take advantage of modern features, without requiring re-writes. + + +### What template syntax does Stencil use? + +Stencil uses [JSX](https://react.dev/learn/writing-markup-with-jsx), a markup language popularized by the React library. + + +### Can Stencil components be lazy loaded? + +Yes! Lazy loading components helps to reduce application startup times, decrease bundle sizes, and improve distribution. + +Because users are able to dynamically load only what is used, startup times are drastically reduced and users only load exactly what their application’s first paint requires. + +At the same time, components built with Stencil can still be imported and consumed by traditional bundlers. + + +### Why are Stencil components written with TypeScript? + +Stencil was originally built for Ionic, and in our experience we’ve found TypeScript to be a valuable tool for maintaining a large codebase across multiple teams. + + +### What dependencies does the Stencil runtime have? + +None. The code generated by Stencil does not rely on Stencil, but rather it generates highly-optimized, framework-free, stand-alone code which runs natively in the browser. + + +### Can data be passed to Web Components? + +Just like any other DOM element in a webpage, any data in the form of arrays, objects, strings and numbers can be passed to element properties. Stencil is designed from the ground up to ensure this capability stays unlocked for application developers. + + +### What technology is Stencil built with? + +The Stencil compiler is built with TypeScript and is [distributed on npm](https://www.npmjs.com/package/@stencil/core). Its distribution includes types, making it easier for developers to use Stencil APIs. + + +## Capabilities + +### Where can Stencil components be used? + +One great advantage of using Web Components is that your component library will work across all projects, not just desktop web apps. + +For example, using a hybrid mobile framework like Ionic, you can deploy Web Components across just about any platform or device, from native iOS and Android apps, to Electron and desktop web apps, and even Progressive Web Apps. + + +### What are the limitations of Web Components? + +The [Web Component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) specs are purposely low-level, and on their own, they do not provide a framework quality developer experience. Web Components run on a fairly primitive set of standards, so you will need a little help to get them to meet your objectives. + +Some limitations include: + +When you try to use pure vanilla Web Components in an application, functionality like server-side rendering and progressive enhancement is not supported by default, and +some out-of-date clients don’t support the Web Components standard. + +In addition, while Web Components technically work with any framework, there are some limitations like lack of type support and input bindings, and challenges passing properties to components, as noted above. + +The good news is that, with help from open source tools like Stencil, you can overcome all of these challenges. Stencil includes framework bindings for Angular, React, and Vue, so you can easily import Web Component libraries into any framework, and interact with them just like they were native to that framework, with all the functionality you’re used to. + + +### What are framework bindings? + +While Web Components can be paired with any JavaScript framework, Stencil has built-in special-purpose bindings to deliver the more advanced features enterprise teams expect when building applications in Angular, React, and Vue. + + +### What features does Stencil add to Web Components? + +Web Components by themselves weren't enough to provide a quality development experience. Building fast web apps required innovations that were previously locked up inside traditional web frameworks. Stencil was built to pull these features out of traditional frameworks and bring them to the fast emerging Web Component standard. + +Compared to using Web Components directly, Stencil provides extra APIs that make writing fast components simpler. APIs like Virtual DOM, JSX, and async rendering make fast, powerful components easy to create, while still maintaining 100% compatibility with Web Components. + + +### What browsers can support Stencil components? + +Stencil works on modern browsers. + +[Learn more about browser support](./support-policy.md#browser-support). + + +## Stencil Project + +### How do I get involved? + +Stencil is an open source project, and we encourage you to contribute. You can start by creating issues on GitHub, submitting feature requests, and helping to replicate bugs. If you’re interested in contributing, please see our [Contributor Guide](https://github.com/ionic-team/stencil/blob/main/.github/CONTRIBUTING.md) and check out our [issue tracker](https://github.com/ionic-team/stencil/issues). + + +### Is Stencil open source? + +Yes, Stencil is open source and its source code can be [found on GitHub](https://github.com/ionic-team/stencil). Contributions are welcomed from the community. + +### Which software license does Stencil use? + +Stencil’s software [license is MIT](https://github.com/ionic-team/stencil/blob/main/LICENSE.md). + + +### Who works on Stencil? + +The majority of the development is done by engineers at [Ionic](https://github.com/ionic-team/ionic). If you’re excited about Stencil, we encourage you to join the community and contribute! Best place to start is on the [discord channel](https://chat.stenciljs.com/). + diff --git a/versioned_docs/version-v4.20/reference/support-policy.md b/versioned_docs/version-v4.20/reference/support-policy.md new file mode 100644 index 000000000..05141a894 --- /dev/null +++ b/versioned_docs/version-v4.20/reference/support-policy.md @@ -0,0 +1,154 @@ +--- +title: Support Policy +sidebar_label: Support Policy +description: Support Policy +slug: /support-policy +--- + +# Support Policy + +## Community Maintenance + +Stencil is a 100% open source (MIT) project. Developers can ensure Stencil is the right choice for building web +components through Ionic’s community maintenance strategy. The Stencil team regularly ships new releases, bug fixes, and +is welcoming to community pull requests. + +## Stencil Maintenance and Support Status + +Given the reality of time and resource constraints as well as the desire to keep innovating in the frontend development +space, over time it becomes necessary for the Stencil team to shift focus to newer versions of the library. However, the +Stencil team will do everything it can to make the transition to newer versions as smooth as possible. The Stencil team +recommends updating to the newest version of the Stencil for the latest features, improvements and stability updates. + +The current status of each Stencil version is: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:----------------:|:------------:|:----------------:|:-----------------:| +| V4 | **Active** | Jun 26, 2023 | TBD | TBD | +| V3 | Extended Support | Jan 25, 2023 | Dec 26, 2023 | Jun 26, 2024 | +| V2 | End of Support | Aug 08, 2020 | Jul 25, 2023 | Jan 25, 2024 | +| V1 | End of Support | Jun 03, 2019 | Aug 08, 2020 | Aug 08, 2020 | + +**Maintenance Period**: Only critical bug and security fixes. No major feature improvements. + +**Extended Support Period**: Available to Stencil Enterprise customers. + +### Stencil Support Details + +Starting with Stencil v2, the Stencil team is adopting a newly revised maintenance policy. When a new major version of +Stencil is released, the previous major version release will enter maintenance mode. While a version of Stencil is in +maintenance mode, only critical bug & security fixes will be applied to that version, and no major feature improvements +will be added. The maintenance period shall last six months from the release of the new major version. + +Once the maintenance period has ended for a version of Stencil, that version enters the extended support period. During +the extended support period, only critical bug and security fixes will be applied for teams and organizations using +Stencil's Enterprise offerings. The extended support period lasts for twelve months from the release of the new major +version. + +The table below describes a theoretical timeline of releases: + +| Version | Status | Released | Maintenance Ends | Ext. Support Ends | +|:-------:|:---------------------:|:------------:|:----------------:|:-----------------:| +| D | Active | Jan 01, 2022 | TBD | TBD | +| C | Maintenance | Jul 07, 2021 | Jul 01, 2022 | Jan 01, 2023 | +| B | Extended Support Only | Jan 01, 2021 | Jan 07, 2022 | Jul 07, 2022 | +| A | End of Support | Jul 07, 2020 | Jul 01, 2021 | Jan 01, 2021 | + +In the example above, when Version D is released, Version C enters maintenance mode. Version D was released on January +1st, 2022. Version C shall be in maintenance mode until July 1st, 2022, three months after the release of Version D. +After July 1st 2022, Version C will be in extended support until Jun 1st, 2023, twelve months after the release of +Version D. + +## Browser Support + +Stencil builds Web Components that run natively in all widely used desktop and mobile browsers. +Custom Elements are natively supported in Chrome, Edge, Firefox, and Safari (including iOS)! + +Stencil supports the following browsers: + +| Stencil Version | Chrome | Edge | Firefox | Safari | Internet Explorer | Pre-Chromium Edge | +|:---------------:|:------:|:----:|:-------:|:------:|:-----------------:|:-----------------:| +| V4 | v79+ | v79+ | v70+ | v14+ | ❌ | ❌ | +| V3 | v79+ | v79+ | v70+ | v14+ | ✅ | ✅ | +| V2 | v60+ | v79+ | v63+ | v10.1+ | ✅ | ✅ | + +## TypeScript Support + +Stencil acts as a compiler for a project's web components, and works closely with the TypeScript compiler to transform +TSX to vanilla JavaScript. To ensure compatibility between the two, Stencil takes an opinionated stance on which version +of the TypeScript compiler must be used. + +Stencil includes a recent copy of the TypeScript compiler in its distributable* to guarantee this compatibility. +The Stencil team is committed to keeping its version of TypeScript up to date and, as of Stencil v2.10.0, attempts to be +within one minor version of the latest TypeScript release. + +The table below describes recent versions of Stencil and the version of TypeScript each version shipped with. + +| Stencil Version | TypeScript Version | +|:---------------:|:------------------:| +| v4.16.0 | v5.4.5 | +| v4.15.0 | v5.4.4 | +| v4.14.0 | v5.4.3 | +| v4.13.0 | v5.4.2 | +| v4.10.0 | v5.3.0 | +| v4.4.0 | v5.2.2 | +| v4.2.0 | v5.1.6 | +| v3.3.0 | v5.0.4 | +| v3.0.0 | v4.9.4 | +| v2.21.0 | v4.9.3 | +| v2.20.0 | v4.8.4 | +| v2.18.0 | v4.7.4 | +| v2.14.0 | v4.5.4 | +| v2.10.0 | v4.3.5 | +| v2.5.0 | v4.2.3 | +| v2.4.0 | v4.1.3 | +| v2.2.0 | v4.0.5 | + +The TypeScript team releases a new minor version of the TypeScript compiler approximately once every three months. To +accomplish its goal of staying within one minor version of the latest release, Stencil will update its version of +TypeScript once every three months as well. Updates to the version of TypeScript will often, but not always, occur in a +[minor version release](./versioning.md#minor-release) of Stencil. + +The Stencil team acknowledges that TypeScript minor version releases may contain breaking changes. The Stencil team will +do everything in its power to avoid propagating breaking changes to its user base. + +\* The TypeScript compiler is never included in the output of your Stencil project, and is only used for compilation +and type checking purposes. + +## Compatibility Recommendations + +Stencil is in many regards an opinionated library, and includes much of the software necessary to get users building web +components as quickly as possible. There are a few pieces of software that Stencil allows users to choose to best fit +their team, organizational structure, and existing technical stack. The Stencil team has compiled a series of +compatibility tables to describe the interoperability requirements of these pieces of software and Stencil. + +### JavaScript Runtime + +| Stencil Version | Node v10 | Node v12 | Node v14 | Node v16 | Node v18 | Node v20 | Node v22 | +|:---------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| +| V4 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| V3 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | +| V2 | ❌ | ✅ | ✅ | ✅ | ⚠ | ❌ | ❌ | +| V1 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | + +### Testing Libraries + +#### Jest + +| Stencil Version | Jest v24-26 | Jest v27 | Jest v28 * | Jest v29 * | +|:---------------:|:-----------:|:--------:|:----------:|:-----------:| +| V4 | ✅ | ✅ | ✅ | ✅ | +| V3 | ✅ | ✅ | ❌ | ❌ | +| V2 | ✅ | ✅ | ❌ | ❌ | +| V1 | ✅ | ❌ | ❌ | ❌ | + +\* Support for Jest 28 & 29 has been included since Stencil v4.7.0. + +#### Puppeteer + +| Stencil Version | Puppeteer v5-9 | Puppeteer v10 | Puppeteer v11-21 | +|:---------------:|:--------------:|:-------------:|:----------------:| +| V4 | ❌ | ✅ | ✅ | +| V3 | ❌ | ✅ | ✅ | +| V2 | ✅ | ✅ | ❌ | +| V1 | ✅ | ❌ | ❌ | diff --git a/versioned_docs/version-v4.20/reference/versioning.md b/versioned_docs/version-v4.20/reference/versioning.md new file mode 100644 index 000000000..09d81c7dd --- /dev/null +++ b/versioned_docs/version-v4.20/reference/versioning.md @@ -0,0 +1,44 @@ +--- +title: Versioning +sidebar_label: Versioning +description: Versioning +slug: /versioning +--- + +# Versioning + +Stencil follows the
    Semantic Versioning (SemVer) convention: +major.minor.patch. Incompatible API changes increment the major version, adding +backwards-compatible functionality increments the minor version, and backwards-compatible bug fixes +increment the patch version. + +## Release Schedule + +### Major Release + +A major release will be published when there is a breaking change introduced in the API. Major releases will occur +roughly every **6 months** and may contain breaking changes. Release candidates will be published prior to a major +release in order to get feedback before the final release. An outline of what is changing and why will be included with +the release candidates. + +### Minor Release + +A minor release will be published when a new feature is added or API changes that are non-breaking are introduced. +We will heavily test any changes so that we are confident with the release, but with new code comes the potential for +new issues*. Minor releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. + +\* This statement applies to the Stencil team upgrading its version of TypeScript as well. For more information, please +see the team's [support policy regarding TypeScript](./support-policy.md#typescript-support) + +### Patch Release + +A patch release will be published when bug fixes were included, but the API has not changed and no breaking changes were +introduced. Patch releases are scheduled to occur at least **once a month**, although this cadence may vary according +to team priorities. There may be times where patch releases need to released more often than scheduled. + +## Changelog + +To see a list of all notable changes to Stencil, please refer to the [releases +page](https://github.com/ionic-team/stencil/releases). This contains an ordered +list of all bug fixes and new features under each release. diff --git a/versioned_docs/version-v4.20/static-site-generation/01-overview.md b/versioned_docs/version-v4.20/static-site-generation/01-overview.md new file mode 100644 index 000000000..3509f33e2 --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/01-overview.md @@ -0,0 +1,49 @@ +--- +title: Static Site Generation +sidebar_label: Overview +slug: /static-site-generation +--- + +# Static Site Generation with Stencil + +One of the best ways to build fast, interactive web sites and web apps is to utilize Static Site Generation instead of Server Side Rendering (known as SSR) or Client Side Rendering (known as Single Page Apps, or SPAs). + +Static Site Generation (SSG) means building and rendering components and routes at build time (aka prerendering) rather than server request time (SSR) or at client run-time (SPA). Because a route is already prerendered, all of the content for the route is available to search engines and clients _immediately_, so SEO and performance are maximized. + +Static Site Generation doesn't mean your pages have to be and/or _stay_ static! Stencil utilizes hydration to efficiently load client-side components at runtime to get the best of both worlds. + +Since Static Site Generation prerenders components, there are some tradeoffs and things to keep in mind, but most components can be easily prerendered without much modification. + +Stencil makes SSG easy, so read on to see how to incorporate it into your apps. + +## Benefits of Static Site Generation + +- Great [Lighthouse](https://developers.google.com/web/tools/lighthouse/) scores +- Faster time to [Largest Contentful Paint (LCP)](https://web.dev/lcp/) +- Better [Search Engine Optimization (SEO)](https://support.google.com/webmasters/answer/7451184) +- Provides functionality for users with JavaScript disabled + +## How Static Site Generation and Prerendering Works + +**Build Hydrate App**: The first step in prerendering is for the compiler to generate a "hydrate" app, which is a single directory to be used by Node.js. The "hydrate" app is automatically generated when the `--prerender` CLI flag is provided and by default the app is saved to `dist/hydrate`. Prerendering uses the hydrate app internally, however it can be used directly at a lower-level. [Learn more about the Hydrate App](../guides/hydrate-app.md) + +**Fork Prerender Tasks to Available CPUs**: Stencil can efficiently divide out the prerendering to each of the current machine's CPUs using [Node.js' Child Process API](https://nodejs.org/api/child_process.html). By tasking each CPU on the machine, the compiler can drastically speed up prerendering times. + +**Prerender Index**: After the compiler has completed the build and created child processes on each available CPU, it will then kick off the prerendering by starting at the single base URL, or the configured entry URLs. Once the page has finished prerendering it'll be written to the configured `www` directory as an `index.html` file. + +**Crawl App**: During each page prerender, Stencil also collects the anchor elements and URLs used within the page. With this information, it's able to inform the main thread of which pages should be prerendered next. The main thread is in charge of orchestrating all of the URLs, and the job is finished once all of the pages have been crawled and prerendered. + +**Deploy Static Files to Production**: Now that all of the pages have been prerendered and written as static HTML files, the `www` directory can now be deployed to a server. A significant difference from prerendering and Server-side Rendering (SSR), is that the HTTP server is just serving up static HTML files rather than dynamically generating the HTML on the server. + +**Static HTML Response**: With the static HTML files deploy to a server, visitors of each prerendered page first receive the HTML with inline styles, and no blocking JS or CSS. Additionally, the compiler is already aware of the exact modules the visitor will need for this page, and will asynchronously preload the modules using [link `modulepreload`](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload). + +**Client-side Hydration**: After the HTML and inlined styles have rendered the first paint, the next step is for the same nodes within the DOM to be hydrated by the client-side JavaScript. Each component within the page will asynchronously hydrate using the initial order they were found in the DOM structure. Next, as each component lazily hydrates they're able to reuse the existing nodes found in the DOM. + +## Tooling + +To be clear, Stencil does _not_ use `Puppeteer` or `jsdom` for prerendering. Puppeteer is great for End-to-End +testing, but for performance reasons it's not ideal to quickly generate a large website with hundreds or thousands of pages. Additionally, `jsdom` is often used for unit testing, but in our experience it's difficult to use with async components and its global environment nature. + +Instead, Stencil uses its own internal DOM APIs which strictly follow the web standards, but optimized for prerendering, Static Site Generation and Server-side Rendering. By doing so, developers can still use all the same APIs they're already familiar with, but they'll seamlessly work within a NodeJS environment too. This means developers often do not have to write code differently in how they're building components, but rather they focus only on writing one type of component, and coding it using the standards they already know. To reiterate, developers do not have to learn a new API for prerendering. It's just the same web APIs your components are already using. + +Every component, machine and environment will perform differently, so it's difficult to provide a consistent benchmark. However, what we do know is that [Ionic's Documentation site](https://ionicframework.com/docs) has hundreds of pages and Stencil is able to prerender the entire site in a few seconds. diff --git a/versioned_docs/version-v4.20/static-site-generation/_category_.json b/versioned_docs/version-v4.20/static-site-generation/_category_.json new file mode 100644 index 000000000..000fe5643 --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Static Site Generation", + "position": 4 +} diff --git a/versioned_docs/version-v4.20/static-site-generation/basics.md b/versioned_docs/version-v4.20/static-site-generation/basics.md new file mode 100644 index 000000000..573c5aa52 --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/basics.md @@ -0,0 +1,72 @@ +--- +title: Static Site Generation Basics in Stencil +sidebar_label: Basics +description: Quick introduction to configuring and using Static Site Generation in Stencil +slug: /static-site-generation-basics +--- + +# Static Site Generation Basics + +Rendering components at build time (rather than purely server or client-time), can add significant performance improvements to your app, and maximize SEO impact. + +Using Static Site Generation in Stencil requires running a build command, returning promises from component lifecycle methods that fetch dynamic data, and ensuring all known URLs are properly discovered and built. + +## Static Build + +Stencil doesn't prerender components by default. However, the build can be made to prerender using the `--prerender` flag: + +```bash +stencil build --prerender +``` + +## Rendering Dynamic Data + +Many components need to render based on data fetched from a server. Stencil handles this by allowing components to return `Promise`'s from lifecycle methods like `componentWillLoad` (this can be achieved by using `async/await` as well). + +For example, this is how to have Stencil wait to render a component until it fetches data from the server: + +```typescript +async componentWillLoad() { + const ret = await fetch('https://.../api'); + + this.thing = await ret.json(); +} +``` + +## Integration with a Router + +Since Stencil will actually navigate to and execute components, it has full support for a router, including Stencil Router. + +There are no changes necessary to access route params and matches. However, make sure your routes can accept a trailing slash as prerendered static content will be treated as loading an `index.html` file at that path, and so the browser may append a trailing slash. + +In particular, if using Stencil Router, double check usage of `exact={true}` which could cause your routes to not match when loaded with a trailing slash. + +## Page and URL Discovery + +By default, Stencil crawls your app starting at base URL of `/` and discovers all paths that need to be indexed. By default this will only discover pages that are linked at build time, but can be easily configured to build any possible URL for the app. + +As each page is generated and new links are found, Stencil will continue to crawl and prerender pages. + +See the [prerender config](./prerender-config.md) docs to see how this can be customized further. + + +## Things to Watch For + +There may be some areas of your code that should absolutely not run while prerendering. To help avoid certain code Stencil provides a `Build.isBrowser` build conditional to tell prerendering to skip over. Here is an example of how to use this utility: + +```tsx +import { Build } from '@stencil/core'; + +connectedCallback() { + // Build.isBrowser is true when running in the + // browser and false when being prerendered + + if (Build.isBrowser) { + console.log('running in browser'); + } else { + console.log('running in node while prerendering'); + } +} +``` + +Also note that the actual runtime generated for the browser builds will not include code that has been excluded because of the `if (Build.isBrowser)` statement. In the above example, only `console.log('running in browser')` would be included within the component's runtime. diff --git a/versioned_docs/version-v4.20/static-site-generation/deployment.md b/versioned_docs/version-v4.20/static-site-generation/deployment.md new file mode 100644 index 000000000..b76972bcd --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/deployment.md @@ -0,0 +1,16 @@ +--- +title: Deploying a Static Site +sidebar_label: Deployment +description: Deploying a Static Site +slug: /static-site-generation-deployment +--- + +# Deploying a Stencil Static Site + +Deploying a prerendered static site built with Stencil is exactly like deploying any static site, because the output is just a set of HTML files. + +Every path that Stencil detects (or is provided using `entryUrls` in the prerender config) is generated in the `www` output target's directory, with each url given an `index.html` that becomes the root for the app. + +Think of it as turning every URL in your app into a standalone web page that bootstraps the entire app. No matter what URL a visitor comes to, they will be served an `index.html` file with that page's specific content already rendered, but with the entire app then hydrating and loading. + +This means you can simply deploy the `www` output target's directory to any static host! \ No newline at end of file diff --git a/versioned_docs/version-v4.20/static-site-generation/meta.md b/versioned_docs/version-v4.20/static-site-generation/meta.md new file mode 100644 index 000000000..606e49072 --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/meta.md @@ -0,0 +1,37 @@ +--- +title: SEO Meta Tags in SSG +sidebar_label: Meta tags +description: Managing meta tags for SEO and social media embedding in Stencil Static Sites +slug: /static-site-generation-meta-tags +--- + +# SEO Meta Tags and Static Site Generation + +Web Apps need to list detailed meta information about content in order to maximize SEO and provide good social media embed experiences. + +One of the benefits to Stencil's prerendering is that most DOM apis are available in the NodeJS environment too. +For example, to set the document title, simply run `document.title = "Page Title"`. +Similarly, meta tags can be set using standard DOM APIs as found in the browser, such as `document.head` and `document.createElement('meta')`. +For this reason, your component's runtime can take care of much of this custom work during prerendering. + +That said, the Prerender Config also includes options that allow individual pages to be modified arbitrarily during prerendering. +For example, the `afterHydrate(document, url)` hook can be used to update the parsed `document` before it is serialized into an HTML string. +The `document` argument is a [standard `Document`](https://developer.mozilla.org/en-US/docs/Web/API/Document), while the `url` argument is a [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) for the location of the page being rendered. + +In the example below, the `afterHydrate(document, url)` hook is setting the document title from url's pathname. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + afterHydrate(document, url) { + document.title = url.pathname; + } +}; +``` + +## @stencil/helmet + +The `@stencil/helmet` package was a library for managing meta tags dynamically. +It has since been deprecated. +For additional information regarding this package, please see its [GitHub page](https://github.com/ionic-team/stencil-helmet) diff --git a/versioned_docs/version-v4.20/static-site-generation/prerender-config.md b/versioned_docs/version-v4.20/static-site-generation/prerender-config.md new file mode 100644 index 000000000..c94144943 --- /dev/null +++ b/versioned_docs/version-v4.20/static-site-generation/prerender-config.md @@ -0,0 +1,106 @@ +--- +title: Prerender Config +sidebar_label: Prerender Config +description: Prerender Config +slug: /prerender-config +--- + + +# Prerender Config for Static Site Generation (SSG) + +As of `1.13.0`, the optional prerender config can be used while prerendering a `www` output target. The `prerender.config.ts` file can further update the parsed document of each page, before it is serialized to HTML. + +Within `stencil.config.ts`, set the path to the prerendering config file path using the `prerenderConfig` +property, such as: + +```tsx +import { Config } from '@stencil/core'; + +export const config: Config = { + outputTargets: [ + { + type: 'www', + baseUrl: 'https://stenciljs.com/', + prerenderConfig: './prerender.config.ts', + } + ] +}; +``` + +Next, inside of the `prerender.config.ts` file, it should export a `config` object using the `PrerenderConfig` interface. + +```tsx +import { PrerenderConfig } from '@stencil/core'; +export const config: PrerenderConfig = { + ... +}; +``` + +| Config | Description | Default | +|--------|-------------|---------| +| `afterHydrate(document, url)` | Run after each `document` is hydrated, but before it is serialized into an HTML string. Hook is passed the `document` and its `URL`. | | +| `beforeHydrate(document, url)` | Run before each `document` is hydrated. Hook is passed the `document` it's `URL`. | | +| `afterSerializeTemplate(html)` | Runs after the template Document object has serialize into an HTML formatted string. Returns an HTML string to be used as the base template for all prerendered pages. | | +| `beforeSerializeTemplate(document)` | Runs before the template Document object is serialize into an HTML formatted string. Returns the Document to be serialized which will become the base template html for all prerendered pages. | | +| `canonicalUrl(url)` | A hook to be used to generate the canonical `` tag which goes in the `` of every prerendered page. Returning `null` will not add a canonical url tag to the page. | | +| `crawlUrls` | While prerendering, crawl same-origin URLs found within `` elements. | `true` | +| `entryUrls` | URLs to start the prerendering from. By default the root URL of `/` is used. | `['/']` | +| `filterAnchor(attrs, base)` | Return `true` the given `` element should be crawled or not. | | +| `filterUrl(url, base)` | Return `true` if the given URL should be prerendered or not. | | +| `filePath(url, filePath)` | Returns the file path which the prerendered HTML content should be written to. | | +| `hydrateOptions(url)` | Returns the hydrate options to use for each individual prerendered page. | | +| `loadTemplate(filePath)` | Returns the template file's content. The template is the base HTML used for all prerendered pages. | | +| `normalizeUrl(href, base)` | Used to normalize the page's URL from a given a string and the current page's base URL. Largely used when reading an anchor's `href` attribute value and normalizing it into a `URL`. | | +| `staticSite` | Static Site Generated (SSG). Does not include Stencil's client-side JavaScript, custom elements or preload modules. | `false` | +| `trailingSlash` | If the prerendered URLs should have a trailing "/"" or not | `false` | + + +## Individual Page Hydrate Options + +Beyond settings for the entire prerendering process with `prerender.config.ts`, you can also +set individual hydrate options per each page. The `hydrateOptions(url)` hook can be used to further configure each page. Below is an example of the prerender config with the `hydrateOptions()` hook, which returns options for each page. + +```tsx +import { PrerenderConfig } from '@stencil/core'; + +export const config: PrerenderConfig = { + hydrateOptions(url) { + return { + prettyHtml: true + }; + } +}; + + +``` +| Option | Description | Default | +|--------|-------------|---------| +| `addModulePreloads` | Adds `` for modules that will eventually be requested. | `true` | +| `approximateLineWidth` | Sets an approximate line width the HTML should attempt to stay within. Note that this is "approximate", in that HTML may often not be able to be split at an exact line width. Additionally, new lines created is where HTML naturally already has whitespace, such as before an attribute or spaces between words. | `100` | +| `canonicalUrl` | Sets the `href` attribute on the `` tag within the ``. If the value is not defined it will ensure a canonical link tag is no included in the ``. | | +| `clientHydrateAnnotations` | Include the HTML comments and attributes used by the client-side JavaScript to read the structure of the HTML and rebuild each component. | `true` | +| `constrainTimeouts` | Constrain `setTimeout()` to 1ms, but still async. Also only allows `setInterval()` to fire once, also constrained to 1ms. | `true` | +| `cookie` | Sets `document.cookie`. | | +| `direction` | Sets the `dir` attribute on the top level ``. | | +| `excludeComponents` | Component tag names listed here will not be prerendered, nor will hydrated on the client-side. Components listed here will be ignored as custom elements and treated no differently than a `
    `. | | +| `inlineExternalStyleSheets` | External stylesheets from `` are instead inlined into `