Skip to content

Commit

Permalink
chore: fix runtime-vapor dts build
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 3, 2025
1 parent ddfd836 commit b20bcf1
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 46 deletions.
5 changes: 1 addition & 4 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,9 @@ type NormalizedProp = PropOptions & {
/**
* normalized value is a tuple of the actual normalized options
* and an array of prop keys that need value casting (booleans and defaults)
* @internal
*/
export type NormalizedProps = Record<string, NormalizedProp>
/**
* @internal
*/

export type NormalizedPropsOptions = [NormalizedProps, string[]] | []

export function initProps(
Expand Down
22 changes: 13 additions & 9 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,22 @@ export const DeprecationTypes = (
// **IMPORTANT** These APIs are exposed solely for @vue/runtime-vapor and may
// change without notice between versions. User code should never rely on them.

/**
* these types cannot be marked internal because runtime-vapor's type relies on
* them, but they should be considered internal
* @private
*/
export {
type ComponentInternalOptions,
type GenericComponentInstance,
type LifecycleHook,
} from './component'
export { type NormalizedPropsOptions } from './componentProps'

/**
* @internal
*/
export {
type NormalizedPropsOptions,
baseNormalizePropsOptions,
resolvePropValue,
validateProps,
Expand All @@ -507,14 +518,7 @@ export { type SchedulerJob, queueJob, flushOnAppMount } from './scheduler'
/**
* @internal
*/
export {
type ComponentInternalOptions,
type GenericComponentInstance,
type LifecycleHook,
expose,
nextUid,
validateComponentName,
} from './component'
export { expose, nextUid, validateComponentName } from './component'
/**
* @internal
*/
Expand Down
14 changes: 10 additions & 4 deletions packages/runtime-vapor/__tests__/block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Fragment, insert, normalizeBlock, prepend, remove } from '../src/block'
import {
VaporFragment,
insert,
normalizeBlock,
prepend,
remove,
} from '../src/block'

const node1 = document.createTextNode('node1')
const node2 = document.createTextNode('node2')
Expand All @@ -13,7 +19,7 @@ describe('block + node ops', () => {
node2,
node3,
])
const frag = new Fragment(node2)
const frag = new VaporFragment(node2)
frag.anchor = anchor
expect(normalizeBlock([node1, frag, [node3]])).toEqual([
node1,
Expand All @@ -39,14 +45,14 @@ describe('block + node ops', () => {
test('prepend', () => {
const container = document.createElement('div')
prepend(container, [node1], node2)
prepend(container, new Fragment(node3))
prepend(container, new VaporFragment(node3))
expect(Array.from(container.childNodes)).toEqual([node3, node1, node2])
})

test('remove', () => {
const container = document.createElement('div')
container.append(node1, node2, node3)
const frag = new Fragment(node3)
const frag = new VaporFragment(node3)
remove([node1], container)
remove(frag, container)
expect(Array.from(container.childNodes)).toEqual([node2])
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-vapor/src/apiCreateDynamicComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveDynamicComponent } from '@vue/runtime-dom'
import { DynamicFragment, type Fragment } from './block'
import { DynamicFragment, type VaporFragment } from './block'
import { createComponentWithFallback } from './component'
import { renderEffect } from './renderEffect'
import type { RawProps } from './componentProps'
Expand All @@ -10,7 +10,7 @@ export function createDynamicComponent(
rawProps?: RawProps | null,
rawSlots?: RawSlots | null,
isSingleRoot?: boolean,
): Fragment {
): VaporFragment {
const frag = __DEV__
? new DynamicFragment('dynamic-component')
: new DynamicFragment()
Expand Down
13 changes: 9 additions & 4 deletions packages/runtime-vapor/src/apiCreateFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
} from '@vue/reactivity'
import { getSequence, isArray, isObject, isString } from '@vue/shared'
import { createComment, createTextNode } from './dom/node'
import { type Block, Fragment, insert, remove as removeBlock } from './block'
import {
type Block,
VaporFragment,
insert,
remove as removeBlock,
} from './block'
import { warn } from '@vue/runtime-dom'
import { currentInstance, isVaporComponent } from './component'
import type { DynamicSlot } from './componentSlots'
import { renderEffect } from './renderEffect'

class ForBlock extends Fragment {
class ForBlock extends VaporFragment {
scope: EffectScope | undefined
key: any

Expand Down Expand Up @@ -64,13 +69,13 @@ export const createFor = (
isComponent = false,
once?: boolean,
// hydrationNode?: Node,
): Fragment => {
): VaporFragment => {
let isMounted = false
let oldBlocks: ForBlock[] = []
let newBlocks: ForBlock[]
let parent: ParentNode | undefined | null
const parentAnchor = __DEV__ ? createComment('for') : createTextNode()
const ref = new Fragment(oldBlocks)
const ref = new VaporFragment(oldBlocks)
const instance = currentInstance!

if (__DEV__ && !instance) {
Expand Down
10 changes: 5 additions & 5 deletions packages/runtime-vapor/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { EffectScope, pauseTracking, resetTracking } from '@vue/reactivity'

export type Block =
| Node
| Fragment
| VaporFragment
| DynamicFragment
| VaporComponentInstance
| Block[]

export type BlockFn = (...args: any[]) => Block

export class Fragment {
export class VaporFragment {
nodes: Block
anchor?: Node

Expand All @@ -26,7 +26,7 @@ export class Fragment {
}
}

export class DynamicFragment extends Fragment {
export class DynamicFragment extends VaporFragment {
anchor: Node
scope: EffectScope | undefined
current?: BlockFn
Expand Down Expand Up @@ -76,8 +76,8 @@ export class DynamicFragment extends Fragment {
}
}

export function isFragment(val: NonNullable<unknown>): val is Fragment {
return val instanceof Fragment
export function isFragment(val: NonNullable<unknown>): val is VaporFragment {
return val instanceof VaporFragment
}

export function isBlock(val: NonNullable<unknown>): val is Block {
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import { setDynamicProps } from './dom/prop'
import {
type DynamicSlotSource,
type RawSlots,
type Slot,
type StaticSlots,
type VaporSlot,
dynamicSlotsProxyHandlers,
getSlot,
} from './componentSlots'
Expand Down Expand Up @@ -97,7 +97,7 @@ export interface ObjectVaporComponent
props?: any,
emit?: EmitFn,
attrs?: any,
slots?: Record<string, Slot>,
slots?: Record<string, VaporSlot>,
): Block

name?: string
Expand Down Expand Up @@ -135,7 +135,7 @@ export type LooseRawProps = Record<
$?: DynamicPropsSource[]
}

type LooseRawSlots = Record<string, Slot | DynamicSlotSource[]> & {
type LooseRawSlots = Record<string, VaporSlot | DynamicSlotSource[]> & {
$?: DynamicSlotSource[]
}

Expand Down
12 changes: 6 additions & 6 deletions packages/runtime-vapor/src/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { currentInstance } from '@vue/runtime-core'
import type { LooseRawProps, VaporComponentInstance } from './component'
import { renderEffect } from './renderEffect'

export type RawSlots = Record<string, Slot> & {
export type RawSlots = Record<string, VaporSlot> & {
$?: DynamicSlotSource[]
}

export type StaticSlots = Record<string, Slot>
export type StaticSlots = Record<string, VaporSlot>

export type Slot = BlockFn
export type DynamicSlot = { name: string; fn: Slot }
export type VaporSlot = BlockFn
export type DynamicSlot = { name: string; fn: VaporSlot }
export type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
export type DynamicSlotSource = StaticSlots | DynamicSlotFn

Expand Down Expand Up @@ -61,7 +61,7 @@ export const dynamicSlotsProxyHandlers: ProxyHandler<RawSlots> = {
export function getSlot(
target: RawSlots,
key: string,
): (Slot & { _bound?: Slot }) | undefined {
): (VaporSlot & { _bound?: VaporSlot }) | undefined {
if (key === '$') return
const dynamicSources = target.$
if (dynamicSources) {
Expand Down Expand Up @@ -112,7 +112,7 @@ const dynamicSlotsPropsProxyHandlers: ProxyHandler<RawProps> = {
export function createSlot(
name: string | (() => string),
rawProps?: LooseRawProps | null,
fallback?: Slot,
fallback?: VaporSlot,
): Block {
const instance = currentInstance as VaporComponentInstance
const rawSlots = instance.rawSlots
Expand Down
10 changes: 2 additions & 8 deletions packages/runtime-vapor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// public APIs
export { createVaporApp } from './apiCreateApp'
export { defineVaporComponent } from './apiDefineComponent'
export { vaporInteropPlugin } from './vdomInterop'

// compiler-use only
export { insert, prepend, remove } from './block'
export {
createComponent,
createComponentWithFallback,
mountComponent,
unmountComponent,
type VaporComponentInstance,
} from './component'
export { createComponent, createComponentWithFallback } from './component'
export { renderEffect } from './renderEffect'
export { createSlot } from './componentSlots'
export { template, children, next } from './dom/template'
Expand Down Expand Up @@ -44,4 +39,3 @@ export {
applySelectModel,
applyDynamicModel,
} from './directives/vModel'
export { vaporInteropPlugin } from './vdomInterop'
3 changes: 3 additions & 0 deletions packages/vue/src/index-with-vapor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// for type generation only
export * from './index'
export * from '@vue/runtime-vapor'
2 changes: 1 addition & 1 deletion rollup.dts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default targetPackages.map(
/** @returns {import('rollup').RollupOptions} */
pkg => {
return {
input: `./temp/packages/${pkg}/src/index.d.ts`,
input: `./temp/packages/${pkg}/src/index${pkg === 'vue' ? '-with-vapor' : ''}.d.ts`,
output: {
file: `packages/${pkg}/dist/${pkg}.d.ts`,
format: 'es',
Expand Down

0 comments on commit b20bcf1

Please sign in to comment.