-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hyrdate): support vdom annotation in nested dsd structures
- Loading branch information
1 parent
6ac07ec
commit f1090ac
Showing
8 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Component, h, Prop } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'page-list-item', | ||
styleUrl: 'page-list-item.css', | ||
shadow: true, | ||
}) | ||
export class MyOtherComponent { | ||
/** | ||
* Set the number to be displayed. | ||
*/ | ||
@Prop() label!: number; | ||
|
||
/** | ||
* Set the number to be displayed. | ||
*/ | ||
@Prop() active = false; | ||
|
||
render() { | ||
const paginationItemClass: any = { | ||
'pagination-item': true, | ||
'active': this.active, | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div class={paginationItemClass}>{this.label}</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:host { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @ts-ignore may not be existing when project hasn't been built | ||
type HydrateModule = typeof import('../../hydrate'); | ||
let renderToString: HydrateModule['renderToString']; | ||
|
||
describe('renderToString', () => { | ||
before(async () => { | ||
// @ts-ignore may not be existing when project hasn't been built | ||
const mod = await import('/hydrate/index.mjs'); | ||
renderToString = mod.renderToString; | ||
}); | ||
|
||
beforeEach(async () => { | ||
const { html } = await renderToString( | ||
`<page-list last-page="5" current-page="1"></page-list>`, | ||
{ serializeShadowRoot: true, prettyHtml: true, fullDocument: false }, | ||
); | ||
const stage = document.createElement('div'); | ||
stage.setAttribute('id', 'stage') | ||
stage.setHTMLUnsafe(html); | ||
document.body.appendChild(stage); | ||
}); | ||
|
||
afterEach(() => { | ||
document.querySelector('#stage')?.remove(); | ||
}); | ||
|
||
it('can hydrate a nested shadow component', async () => { | ||
expect(typeof customElements.get('page-list-item')).toBe('undefined') | ||
|
||
// @ts-expect-error resolved through WDIO | ||
const { defineCustomElements } = await import('/dist/loader/index.js'); | ||
defineCustomElements().catch(console.error); | ||
|
||
// wait for Stencil to take over and reconcile | ||
await browser.waitUntil(async () => customElements.get('page-list-item')); | ||
expect(typeof customElements.get('page-list-item')).toBe('function') | ||
await expect($('page-list')).toHaveText('0\n1\n2\n3\n4'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Component, h, Prop, State } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'page-list', | ||
styleUrl: 'page-list.css', | ||
shadow: true, | ||
}) | ||
export class PatternlibPagination { | ||
|
||
@Prop({ mutable: true }) lastPage: number | null = null; | ||
@State() pages: Array<number> = []; | ||
|
||
private fillPageArray(start: number, num: number): Array<number> { | ||
const pages = []; | ||
for (let i = 0; i < num; i++) { | ||
pages.push(start + i); | ||
} | ||
return pages; | ||
} | ||
|
||
componentWillLoad(): void { | ||
// range guard | ||
this.lastPage = this.lastPage && this.lastPage >= 1 ? this.lastPage : 1; | ||
this.pages = this.fillPageArray(0, this.lastPage); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div class="pagination"> | ||
<div class="pagination-pages pagination-notation"> | ||
{this.pages.map(i => ( | ||
<page-list-item label={i}></page-list-item> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters