import {
+ VaporTeleport,
createComponent,
createIf,
createPlainElement,
}
})
- test.todo('with teleport', async () => {})
+ test('with teleport', async () => {
+ const state = reactive({ color: 'red' })
+ const target = document.createElement('div')
+ document.body.appendChild(target)
+
+ define({
+ setup() {
+ useVaporCssVars(() => state)
+ return createComponent(
+ VaporTeleport,
+ {
+ to: () => target,
+ },
+ {
+ default: () => template('<div></div>', true)(),
+ },
+ )
+ },
+ }).render()
+
+ await nextTick()
+ expect(target.innerHTML).toBe('<div style="--color: red;"></div>')
+
+ state.color = 'green'
+ await nextTick()
+ expect(target.innerHTML).toBe('<div style="--color: green;"></div>')
+ })
test.todo('with teleport in child slot', async () => {})
- test('with teleport(change subTree)', async () => {})
+ test.todo('with teleport(change subTree)', async () => {})
- test('with teleport(disabled)', async () => {})
+ test.todo('with teleport(disabled)', async () => {})
test('with string style', async () => {
const state = reactive({ color: 'red' })
}
mount(target, this.targetAnchor!)
+ updateCssVars(this, false)
} else if (__DEV__) {
warn(
`Invalid Teleport target on ${this.targetAnchor ? 'update' : 'mount'}:`,
// mount into main container
if (isTeleportDisabled(this.resolvedProps!)) {
mount(this.parent, this.anchor!)
+ updateCssVars(this, true)
}
// mount into target container
else {
}
return null
}
+
+function updateCssVars(frag: TeleportFragment, isDisabled: boolean) {
+ const ctx = currentInstance as GenericComponentInstance
+ if (ctx && ctx.ut) {
+ let node, anchor
+ if (isDisabled) {
+ node = frag.placeholder
+ anchor = frag.anchor
+ } else {
+ node = frag.targetStart
+ anchor = frag.targetAnchor
+ }
+ while (node && node !== anchor) {
+ if (node.nodeType === 1)
+ (node as Element).setAttribute('data-v-owner', String(ctx.uid))
+ node = node.nextSibling
+ }
+ ctx.ut()
+ }
+}