Skip to content

Commit 81e6a92

Browse files
feat: vue 3.3 support structural change (#96)
1 parent 4ab9372 commit 81e6a92

File tree

31 files changed

+414
-474
lines changed

31 files changed

+414
-474
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@
6161
"vite": "^4.3.3",
6262
"vite-plugin-dts": "^2.3.0",
6363
"vitest": "^0.30.1",
64-
"vue": "^3.2.47"
64+
"vue": "^3.3.0-beta.5"
6565
},
6666
"packageManager": "[email protected]",
6767
"overrides": {
68-
"vue": "^3.2.47"
68+
"vue": "3.3.0-beta.5"
6969
},
7070
"pnpm": {
7171
"overrides": {
72-
"vue": "^3.2.47",
72+
"vue": "3.3.0-beta.5",
7373
"vite": "^4.3.1"
7474
}
7575
}

packages/components/aspect-ratio/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:fix": "eslint . --fix"
3434
},
3535
"peerDependencies": {
36-
"vue": "^3.2.47"
36+
"vue": "^3.3.0-beta.5"
3737
},
3838
"dependencies": {
3939
"@oku-ui/primitive": "workspace:^",

packages/components/aspect-ratio/src/aspect-ratio.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { ComponentPublicInstance } from 'vue'
22
import { computed, defineComponent, h, ref } from 'vue'
3-
import type { ComponentPropsWithoutRef, ElementRef } from '@oku-ui/primitive'
3+
import type { ElementRef, MergeProps, PrimitiveProps } from '@oku-ui/primitive'
44
import { Primitive } from '@oku-ui/primitive'
5-
import type { MergeProps } from '@oku-ui/utils'
65

7-
type PrimitiveAspectRatioProps = ComponentPropsWithoutRef<typeof Primitive.div>
8-
type AspectRatioElement = ElementRef<typeof Primitive.div>
6+
interface AspectRatioProps extends PrimitiveProps {
7+
ratio?: number
8+
}
9+
10+
type AspectRatioElement = ElementRef<'div'>
911

1012
const NAME = 'AspectRatio'
1113

@@ -19,7 +21,7 @@ const AspectRatio = defineComponent({
1921
},
2022
},
2123
setup(props, { attrs, slots, expose }) {
22-
const { style, ...aspectRatioProps } = attrs as PrimitiveAspectRatioProps
24+
const { style, ...aspectRatioProps } = attrs as AspectRatioElement
2325
const innerRef = ref<ComponentPublicInstance>()
2426

2527
expose({
@@ -61,11 +63,10 @@ const AspectRatio = defineComponent({
6163
},
6264
})
6365

64-
type AspectRatioProps = MergeProps<typeof AspectRatio, PrimitiveAspectRatioProps>
65-
66-
const OkuAspectRatio = AspectRatio as typeof AspectRatio & (new () => { $props: AspectRatioProps })
66+
// TODO: https://github.com/vuejs/core/pull/7444 after delete
67+
type _AspectRatioProps = MergeProps<AspectRatioProps, AspectRatioElement>
6768

68-
type OkuAspectRatioElement = Omit<InstanceType<typeof AspectRatio>, keyof ComponentPublicInstance>
69+
const OkuAspectRatio = AspectRatio as typeof AspectRatio & (new () => { $props: _AspectRatioProps })
6970

7071
export { OkuAspectRatio }
71-
export type { AspectRatioProps, OkuAspectRatioElement }
72+
export type { AspectRatioProps, AspectRatioElement }

packages/components/aspect-ratio/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export {
33
} from './aspect-ratio'
44
export type {
55
AspectRatioProps,
6-
OkuAspectRatioElement,
6+
AspectRatioElement,
77
} from './aspect-ratio'

packages/components/avatar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:fix": "eslint . --fix"
3434
},
3535
"peerDependencies": {
36-
"vue": "^3.2.47"
36+
"vue": "^3.3.0-beta.5"
3737
},
3838
"dependencies": {
3939
"@oku-ui/primitive": "workspace:^",

packages/components/avatar/src/avatar.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { ComponentPublicInstance, PropType } from 'vue'
22
import { computed, defineComponent, h, onMounted, onUnmounted, ref, watch, watchEffect } from 'vue'
3-
import type { ComponentPropsWithoutRef } from '@oku-ui/primitive'
3+
import type { ElementRef, MergeProps, PrimitiveProps } from '@oku-ui/primitive'
44
import { Primitive } from '@oku-ui/primitive'
55
import type { Scope } from '@oku-ui/provide'
66
import { createProvideScope } from '@oku-ui/provide'
77
import { useCallbackRef } from '@oku-ui/use-callback-ref'
8-
import type { MergeProps } from '@oku-ui/utils'
98

109
function useImageLoadingStatus(src?: string) {
1110
const loadingStatus = ref<ImageLoadingStatus>('idle')
@@ -54,9 +53,11 @@ type AvatarProvideValue = {
5453

5554
const [AvatarProvider, useAvatarInject] = createAvatarProvide<AvatarProvideValue>(AVATAR_NAME)
5655

57-
type AvatarElement = ComponentPropsWithoutRef<typeof Primitive.span>
58-
type PrimitiveSpanProps = ComponentPropsWithoutRef<typeof Primitive.span>
59-
type AvatarProps = MergeProps<typeof Avatar, PrimitiveSpanProps>
56+
type AvatarElement = ElementRef<'span'>
57+
58+
interface AvatarProps extends PrimitiveProps {
59+
scopeAvatar?: Scope
60+
}
6061

6162
const Avatar = defineComponent({
6263
name: AVATAR_NAME,
@@ -68,7 +69,7 @@ const Avatar = defineComponent({
6869
},
6970
},
7071
setup(props, { attrs, slots, expose }) {
71-
const { ...avatarProps } = attrs as AvatarProps
72+
const { ...avatarProps } = attrs as AvatarElement
7273
const innerRef = ref()
7374
const imageLoadingStatus = ref<ImageLoadingStatus>('idle')
7475

@@ -103,9 +104,12 @@ const Avatar = defineComponent({
103104

104105
const IMAGE_NAME = 'AvatarImage'
105106

106-
type AvatarImageElement = ComponentPropsWithoutRef<typeof Primitive.img>
107-
type PrimitiveImgProps = ComponentPropsWithoutRef<typeof Primitive.img>
108-
type AvatarImageProps = MergeProps<typeof AvatarImage, PrimitiveImgProps>
107+
type AvatarImageElement = ElementRef<'img'>
108+
109+
interface AvatarImageProps extends PrimitiveProps {
110+
onLoadingStatusChange?: (status: ImageLoadingStatus) => void
111+
scopeAvatar?: Scope
112+
}
109113

110114
const AvatarImage = defineComponent({
111115
name: IMAGE_NAME,
@@ -122,7 +126,7 @@ const AvatarImage = defineComponent({
122126
},
123127
},
124128
setup(props, { attrs, slots, expose }) {
125-
const { src, ...imageProps } = attrs as AvatarImageProps
129+
const { src, ...imageProps } = attrs as AvatarImageElement
126130
const inject = useAvatarInject(IMAGE_NAME, props.scopeAvatar)
127131
const innerRef = ref<ComponentPublicInstance>()
128132
const imageLoadingStatus = useImageLoadingStatus(src)
@@ -169,10 +173,11 @@ const AvatarImage = defineComponent({
169173

170174
const FALLBACK_NAME = 'AvatarFallback'
171175

172-
type PrimitiveAvatarFallbackProps = ComponentPropsWithoutRef<typeof Primitive.span>
173-
type PrimitiveSpanElement = ComponentPropsWithoutRef<typeof Primitive.span>
176+
type AvatarFallbackElement = ElementRef<'span'>
174177

175-
type AvatarFallbackProps = MergeProps<typeof AvatarFallback, PrimitiveAvatarFallbackProps>
178+
interface AvatarFallbackProps extends PrimitiveProps {
179+
delayMs?: number
180+
}
176181

177182
const AvatarFallback = defineComponent({
178183
name: FALLBACK_NAME,
@@ -228,20 +233,21 @@ const AvatarFallback = defineComponent({
228233
}
229234

230235
return originalReturn as unknown as {
231-
innerRef: PrimitiveSpanElement
236+
innerRef: AvatarFallbackElement
232237
}
233238
},
234239
})
235240

236241
/* ----------------------------------------------------------------------------------------------- */
237242

238-
const OkuAvatar = Avatar as typeof Avatar & (new () => { $props: AvatarProps })
239-
const OkuAvatarImage = AvatarImage as typeof AvatarImage & (new () => { $props: AvatarImageProps })
240-
const OkuAvatarFallback = AvatarFallback as typeof AvatarFallback & (new () => { $props: AvatarFallbackProps })
243+
// TODO: https://github.com/vuejs/core/pull/7444 after delete
244+
type _OkuAvatarProps = MergeProps<AvatarProps, AvatarElement>
245+
type _OkuAvatarImageProps = MergeProps<AvatarImageProps, AvatarImageElement>
246+
type _OkuAvatarFallbackProps = MergeProps<AvatarFallbackProps, AvatarFallbackElement>
241247

242-
type OkuAvatarElement = Omit<InstanceType<typeof Avatar>, keyof ComponentPublicInstance>
243-
type OkuAvatarImageElement = Omit<InstanceType<typeof AvatarImage>, keyof ComponentPublicInstance>
244-
type OkuAvatarFallbackElement = Omit<InstanceType<typeof AvatarFallback>, keyof ComponentPublicInstance>
248+
const OkuAvatar = Avatar as typeof Avatar & (new () => { $props: _OkuAvatarProps })
249+
const OkuAvatarImage = AvatarImage as typeof AvatarImage & (new () => { $props: _OkuAvatarImageProps })
250+
const OkuAvatarFallback = AvatarFallback as typeof AvatarFallback & (new () => { $props: _OkuAvatarFallbackProps })
245251

246252
export {
247253
OkuAvatar,
@@ -254,7 +260,7 @@ export type {
254260
AvatarProps,
255261
AvatarImageProps,
256262
AvatarFallbackProps,
257-
OkuAvatarElement,
258-
OkuAvatarImageElement,
259-
OkuAvatarFallbackElement,
263+
AvatarElement,
264+
AvatarImageElement,
265+
AvatarFallbackElement,
260266
}

packages/components/avatar/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type {
88
AvatarFallbackProps,
99
AvatarProps,
1010
AvatarImageProps,
11-
OkuAvatarElement,
12-
OkuAvatarFallbackElement,
13-
OkuAvatarImageElement,
11+
AvatarElement,
12+
AvatarFallbackElement,
13+
AvatarImageElement,
1414
} from './avatar'

packages/components/checkbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:fix": "eslint . --fix"
3434
},
3535
"peerDependencies": {
36-
"vue": "^3.2.47"
36+
"vue": "^3.3.0-beta.5"
3737
},
3838
"dependencies": {
3939
"@oku-ui/compose-refs": "workspace:^",

0 commit comments

Comments
 (0)