Skip to content

Commit a10d1cc

Browse files
authored
fix: formatting in new web-components content (#3114)
1 parent 669f872 commit a10d1cc

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

src/guide/extras/web-components.md

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function register() {
238238
}
239239
```
240240

241-
A consumer can use the elements in a Vue file,
241+
A consumer can use the elements in a Vue file:
242242

243243
```vue
244244
<script setup>
@@ -253,7 +253,7 @@ register()
253253
</template>
254254
```
255255

256-
or in any other framework such as one with JSX, and with custom names:
256+
Or in any other framework such as one with JSX, and with custom names:
257257

258258
```jsx
259259
import { MyFoo, MyBar } from 'path/to/elements.js'
@@ -263,8 +263,8 @@ customElements.define('some-bar', MyBar)
263263

264264
export function MyComponent() {
265265
return <>
266-
<some-foo ...>
267-
<some-bar ...></some-bar>
266+
<some-foo ... >
267+
<some-bar ... ></some-bar>
268268
</some-foo>
269269
</>
270270
}
@@ -293,24 +293,24 @@ customElements.define('some-element', SomeElement)
293293
// Add the new element type to Vue's GlobalComponents type.
294294
declare module 'vue' {
295295
interface GlobalComponents {
296-
// Be sure to pass in the Vue component type here (SomeComponent, *not* SomeElement).
297-
// Custom Elements require a hyphen in their name, so use the hyphenated element name here.
296+
// Be sure to pass in the Vue component type here
297+
// (SomeComponent, *not* SomeElement).
298+
// Custom Elements require a hyphen in their name,
299+
// so use the hyphenated element name here.
298300
'some-element': typeof SomeComponent
299301
}
300302
}
301303
```
302304

303305
## Non-Vue Web Components and TypeScript {#non-vue-web-components-and-typescript}
304306

305-
Here is the recommended way to enable type checking in SFC templates of Custom
306-
Elements that are not built with Vue.
307+
Here is the recommended way to enable type checking in SFC templates of Custom Elements that are not built with Vue.
307308

308309
> [!Note]
309310
> This approach is one possible way to do it, but it may vary depending on the
310311
> framework being used to create the custom elements.
311312
312-
Suppose we have a custom element with some JS properties and events defined, and
313-
it is shipped in a library called `some-lib`:
313+
Suppose we have a custom element with some JS properties and events defined, and it is shipped in a library called `some-lib`:
314314

315315
```ts
316316
// file: some-lib/src/SomeElement.ts
@@ -348,11 +348,9 @@ export class AppleFellEvent extends Event {
348348
}
349349
```
350350

351-
The implementation details have been omitted, but the important part is that we
352-
have type definitions for two things: prop types and event types.
351+
The implementation details have been omitted, but the important part is that we have type definitions for two things: prop types and event types.
353352

354-
Let's create a type helper for easily registering custom element type
355-
definitions in Vue:
353+
Let's create a type helper for easily registering custom element type definitions in Vue:
356354

357355
```ts
358356
// file: some-lib/src/DefineCustomElement.ts
@@ -367,15 +365,17 @@ type DefineCustomElement<
367365
// specifically reads prop definitions from the `$props` type. Note that we
368366
// combine the element's props with the global HTML props and Vue's special
369367
// props.
370-
/** @deprecated Do not use the $props property on a Custom Element ref, this is for template prop types only. */
368+
/** @deprecated Do not use the $props property on a Custom Element ref,
369+
this is for template prop types only. */
371370
$props: HTMLAttributes &
372371
Partial<Pick<ElementType, SelectedAttributes>> &
373372
PublicProps
374373

375374
// Use $emit to specifically define event types. Vue specifically reads event
376375
// types from the `$emit` type. Note that `$emit` expects a particular format
377376
// that we map `Events` to.
378-
/** @deprecated Do not use the $emit property on a Custom Element ref, this is for template prop types only. */
377+
/** @deprecated Do not use the $emit property on a Custom Element ref,
378+
this is for template prop types only. */
379379
$emit: VueEmit<Events>
380380
}
381381

@@ -390,13 +390,12 @@ type VueEmit<T extends EventMap> = EmitFn<{
390390
```
391391
392392
> [!Note]
393-
> We marked `$props` and `$emit` as deprecated so that when we get a `ref` to a
394-
> custom element we will not be tempted to use these properties, as these
393+
> We marked `$props` and `$emit` as deprecated so that when we get a `ref` to
394+
> a custom element we will not be tempted to use these properties, as these
395395
> properties are for type checking purposes only when it comes to custom elements.
396396
> These properties do not actually exist on the custom element instances.
397397
398-
Using the type helper we can now select the JS properties that should be exposed
399-
for type checking in Vue templates:
398+
Using the type helper we can now select the JS properties that should be exposed for type checking in Vue templates:
400399
401400
```ts
402401
// file: some-lib/src/SomeElement.vue.ts
@@ -421,8 +420,7 @@ declare module 'vue' {
421420
}
422421
```
423422

424-
Suppose that `some-lib` builds its source TypeScript files into a `dist/` folder. A user of
425-
`some-lib` can then import `SomeElement` and use it in a Vue SFC like so:
423+
Suppose that `some-lib` builds its source TypeScript files into a `dist/` folder. A user of `some-lib` can then import `SomeElement` and use it in a Vue SFC like so:
426424

427425
```vue
428426
<script setup lang="ts">
@@ -446,7 +444,8 @@ onMounted(() => {
446444
el.value!.someMethod()
447445
)
448446
449-
// Do not use these props, they are `undefined` (IDE will show them crossed out):
447+
// Do not use these props, they are `undefined`
448+
// IDE will show them crossed out
450449
el.$props
451450
el.$emit
452451
})
@@ -467,8 +466,7 @@ onMounted(() => {
467466
</template>
468467
```
469468

470-
If an element does not have type definitions, the types of the properties and events can be
471-
defined in a more manual fashion:
469+
If an element does not have type definitions, the types of the properties and events can be defined in a more manual fashion:
472470

473471
```vue
474472
<script setup lang="ts">
@@ -503,11 +501,7 @@ declare module 'vue' {
503501
</template>
504502
```
505503

506-
Custom Element authors should not automatically export framework-specific custom
507-
element type definitions from their libraries, for example they should not
508-
export them from an `index.ts` file that also exports the rest of the library,
509-
otherwise users will have unexpected module augmentation errors. Users should
510-
import the framework-specific type definition file that they need.
504+
Custom Element authors should not automatically export framework-specific custom element type definitions from their libraries, for example they should not export them from an `index.ts` file that also exports the rest of the library, otherwise users will have unexpected module augmentation errors. Users should import the framework-specific type definition file that they need.
511505

512506
## Web Components vs. Vue Components {#web-components-vs-vue-components}
513507

0 commit comments

Comments
 (0)