-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from Tofandel/fix/ssr-clones
Fix SSR of cloned slides
- Loading branch information
Showing
10 changed files
with
243 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pnpm lint | ||
pnpm test |
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
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,32 @@ | ||
import { cloneVNode, ComponentInternalInstance, h } from 'vue' | ||
|
||
import { Slide } from '@/components/Slide' | ||
|
||
type CreateCloneSlidesArgs = { | ||
slides: Array<ComponentInternalInstance> | ||
position: 'before' | 'after' | ||
toShow: number | ||
} | ||
|
||
export function createCloneSlides({ slides, position, toShow }: CreateCloneSlidesArgs) { | ||
const clones = [] | ||
const isBefore = position === 'before' | ||
const start = isBefore ? -toShow : 0 | ||
const end = isBefore ? 0 : toShow | ||
|
||
for (let i = start; i < end; i++) { | ||
const index = isBefore ? i : slides.length > 0 ? i + slides.length : i + 99999 | ||
const props = { | ||
index, | ||
isClone: true, | ||
key: `clone-${position}-${i}`, | ||
} | ||
clones.push( | ||
slides.length > 0 | ||
? cloneVNode(slides[(i + slides.length) % slides.length].vnode, props) | ||
: h(Slide, props) | ||
) | ||
} | ||
|
||
return clones | ||
} |
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
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
Oops, something went wrong.