diff --git a/nx.json b/nx.json index 342c92a9b..c3c9036f2 100644 --- a/nx.json +++ b/nx.json @@ -7,7 +7,7 @@ "cacheableOperations": [ "build" ], - "parallel": 1 + "parallel": 5 } } }, diff --git a/package.json b/package.json index a0e61faee..cab92957a 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,7 @@ "tailwindcss": "^3.3.3", "tsup": "^7.2.0", "typescript": "^5.1.6", - "unbuild": "^1.2.1", + "unbuild": "^2.0.0-rc.0", "vite": "^4.4.7", "vite-plugin-dts": "^3.5.1", "vitest": "^0.34.1", diff --git a/packages/components/arrow/src/arrow.test.ts b/packages/components/arrow/src/arrow.test.ts index b4711aa3b..be0ff7124 100644 --- a/packages/components/arrow/src/arrow.test.ts +++ b/packages/components/arrow/src/arrow.test.ts @@ -3,17 +3,26 @@ import type { VueWrapper } from '@vue/test-utils' import { mount } from '@vue/test-utils' import { axe } from 'vitest-axe' import type { VueNode } from '@vue/test-utils/dist/types' +import type { Component } from 'vue' +import { h } from 'vue' import { OkuArrow } from './arrow' -const WIDTH = 40 -const HEIGHT = 30 +const component = { + setup(props, { attrs, slots }) { + return () => h(OkuArrow, { ...attrs }, slots) + }, +} as Component + +// TODO: delete any +const WIDTH = 40 as any +const HEIGHT = 30 as any describe('label', () => { let _wrapper: VueWrapper let svg: VueNode beforeEach(() => { - const wrapper = mount(OkuArrow, { + const wrapper = mount(component, { props: { width: WIDTH, height: HEIGHT, diff --git a/packages/components/arrow/src/arrow.ts b/packages/components/arrow/src/arrow.ts index 5c5858701..6ffc66c7f 100644 --- a/packages/components/arrow/src/arrow.ts +++ b/packages/components/arrow/src/arrow.ts @@ -1,25 +1,25 @@ import { cloneVNode, defineComponent, h } from 'vue' -import type { ElementType, IPrimitiveProps, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { Primitive, PrimitiveProps } from '@oku-ui/primitive' +import type { ElementType, PrimitiveProps } from '@oku-ui/primitive' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import { useForwardRef } from '@oku-ui/use-composable' -type ArrowElement = ElementType<'svg'> -export type _ArrowEl = SVGSVGElement +export type ArrowIntrinsicElement = ElementType<'svg'> +export type ArrowElement = SVGSVGElement -interface ArrowProps extends IPrimitiveProps {} +interface ArrowProps extends PrimitiveProps {} -const NAME = 'Arrow' +const NAME = 'OkuArrow' const arrow = defineComponent({ name: NAME, inheritAttrs: false, props: { - ...PrimitiveProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { const forwardedRef = useForwardRef() - const { width = '10px', height = '5px', ...arrowAttrs } = attrs as ArrowElement + const { width = '10px', height = '5px', ...arrowAttrs } = attrs as ArrowIntrinsicElement const originalReturn = () => { const defaultSlot = typeof slots.default === 'function' ? slots.default()[0] : slots.default ?? null @@ -53,10 +53,9 @@ const arrow = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _ArrowProps = MergeProps -type InstanceArrowType = InstanceTypeRef - -const OkuArrow = arrow as typeof arrow & (new () => { $props: _ArrowProps }) +export const OkuArrow = arrow as typeof arrow +& (new () => { + $props: Partial +}) -export { OkuArrow } -export type { ArrowProps, ArrowElement, InstanceArrowType } +export type { ArrowProps } diff --git a/packages/components/arrow/src/index.ts b/packages/components/arrow/src/index.ts index 0b1365608..e22f9c27a 100644 --- a/packages/components/arrow/src/index.ts +++ b/packages/components/arrow/src/index.ts @@ -1,4 +1,4 @@ export { OkuArrow, } from './arrow' -export type { ArrowProps, ArrowElement, InstanceArrowType, _ArrowEl } from './arrow' +export type { ArrowProps, ArrowElement, ArrowIntrinsicElement } from './arrow' diff --git a/packages/components/aspect-ratio/build.config.ts b/packages/components/aspect-ratio/build.config.ts index b972b9a78..7107c4658 100644 --- a/packages/components/aspect-ratio/build.config.ts +++ b/packages/components/aspect-ratio/build.config.ts @@ -5,8 +5,8 @@ export default defineBuildConfig({ { builder: 'mkdist', input: './src/', - pattern: ['**/!(*.test|*.stories).ts'], + pattern: ['**', '!stories'], + declaration: true, }, ], - declaration: true, }) diff --git a/packages/components/aspect-ratio/src/aspect-ratio.test.ts b/packages/components/aspect-ratio/src/aspect-ratio.test.ts index a782615f6..841a0ac2f 100644 --- a/packages/components/aspect-ratio/src/aspect-ratio.test.ts +++ b/packages/components/aspect-ratio/src/aspect-ratio.test.ts @@ -1,16 +1,24 @@ import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import { axe } from 'vitest-axe' +import type { Component } from 'vue' +import { h } from 'vue' import { OkuAspectRatio } from './aspect-ratio' +const component = { + setup(props, { attrs, slots }) { + return () => h(OkuAspectRatio, { ...attrs }, slots) + }, +} as Component + describe('OkuAspectRatio', () => { it('renders the component correctly', () => { - const wrapper = mount(OkuAspectRatio) + const wrapper = mount(component) expect(wrapper.exists()).toBe(true) }) it('should have no accessibility violations', async () => { - const _wrapper = mount(OkuAspectRatio) + const _wrapper = mount(component) const results = await axe(_wrapper.element) // @ts-expect-error toHaveNoViolations add types project diff --git a/packages/components/aspect-ratio/src/aspect-ratio.ts b/packages/components/aspect-ratio/src/aspect-ratio.ts index e5208adc2..656672191 100644 --- a/packages/components/aspect-ratio/src/aspect-ratio.ts +++ b/packages/components/aspect-ratio/src/aspect-ratio.ts @@ -1,16 +1,17 @@ -import { defineComponent, h } from 'vue' -import type { ElementType, IPrimitiveProps, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { Primitive, PrimitiveProps } from '@oku-ui/primitive' +import type { CSSProperties } from 'vue' +import { defineComponent, h, toRef } from 'vue' +import type { ElementType, PrimitiveProps } from '@oku-ui/primitive' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import { useForwardRef } from '@oku-ui/use-composable' -interface AspectRatioProps extends IPrimitiveProps { - ratio?: number -} +export type AspectRatioIntrinsicElement = ElementType<'div'> +export type AspectRatioElement = HTMLDivElement -type AspectRatioElement = ElementType<'div'> -export type _AspectRatioEl = HTMLDivElement +const NAME = 'OkuAspectRatio' -const NAME = 'AspectRatio' +interface AspectRatioProps extends PrimitiveProps { + ratio?: number +} const AspectRatio = defineComponent({ name: NAME, @@ -20,37 +21,37 @@ const AspectRatio = defineComponent({ type: Number, default: 1 / 1, }, - ...PrimitiveProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { - const { style, ...aspectRatioProps } = attrs as AspectRatioElement + const ratio = toRef(props, 'ratio') + const { style, ...aspectRatioAttrs } = attrs as AspectRatioIntrinsicElement const forwardedRef = useForwardRef() - const originalReturn = () => h( 'div', { 'style': { position: 'relative', width: '100%', - paddingBottom: `${100 / props.ratio}%`, - }, + paddingBottom: `${100 / ratio.value}%`, + } as CSSProperties, 'data-oku-aspect-ratio-wrapper': '', }, [ h( Primitive.div, { - ...aspectRatioProps, + asChild: props.asChild, + ...aspectRatioAttrs, ref: forwardedRef, style: { ...(style as any), position: 'absolute', - top: 0, - right: 0, - bottom: 0, - left: 0, + top: '0px', + right: '0px', + left: '0px', + bottom: '0px', }, - asChild: props.asChild, }, { default: () => slots.default?.(), @@ -64,10 +65,9 @@ const AspectRatio = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _AspectRatioProps = MergeProps -type InstanceAspectRatioType = InstanceTypeRef - -const OkuAspectRatio = AspectRatio as typeof AspectRatio & (new () => { $props: _AspectRatioProps }) +export const OkuAspectRatio = AspectRatio as typeof AspectRatio & +(new () => { + $props: Partial +}) -export { OkuAspectRatio } -export type { AspectRatioProps, AspectRatioElement, InstanceAspectRatioType } +export type { AspectRatioProps } diff --git a/packages/components/aspect-ratio/src/index.ts b/packages/components/aspect-ratio/src/index.ts index bed7a582a..1007c4cc4 100644 --- a/packages/components/aspect-ratio/src/index.ts +++ b/packages/components/aspect-ratio/src/index.ts @@ -1,9 +1,6 @@ -export { - OkuAspectRatio, -} from './aspect-ratio' +export { OkuAspectRatio } from './aspect-ratio' export type { AspectRatioProps, AspectRatioElement, - InstanceAspectRatioType, - _AspectRatioEl, + AspectRatioIntrinsicElement, } from './aspect-ratio' diff --git a/packages/components/aspect-ratio/src/stories/AspectRatioDemo.vue b/packages/components/aspect-ratio/src/stories/AspectRatioDemo.vue index b638cb968..5da56f476 100644 --- a/packages/components/aspect-ratio/src/stories/AspectRatioDemo.vue +++ b/packages/components/aspect-ratio/src/stories/AspectRatioDemo.vue @@ -1,9 +1,8 @@ @@ -57,7 +56,7 @@ onMounted(() => {
- + (AVATAR_NAME) +export const [avatarProvider, useAvatarInject] = createAvatarProvide(AVATAR_NAME) -type AvatarElement = ElementType<'span'> -export type _AvatarEl = HTMLSpanElement +export type AvatarIntrinsicElement = ElementType<'span'> +export type AvatarElement = HTMLSpanElement -interface AvatarProps extends IPrimitiveProps { +interface AvatarProps extends PrimitiveProps { scopeAvatar?: Scope } -const Avatar = defineComponent({ +const avatar = defineComponent({ name: AVATAR_NAME, inheritAttrs: false, props: { - scopeAvatar: { - ...ScopePropObject, - }, + ...scopeAvatarProps, }, setup(props, { attrs, slots }) { - const { ...avatarProps } = attrs as AvatarElement + const { ...avatarProps } = attrs as AvatarIntrinsicElement const forwardedRef = useForwardRef() const imageLoadingStatus = ref('idle') - AvatarProvider({ - scope: props.scopeAvatar, + avatarProvider({ + scope: props.scopeOkuAvatar, imageLoadingStatus: imageLoadingStatus.value, onImageLoadingStatusChange: (status: ImageLoadingStatus) => { imageLoadingStatus.value = status @@ -61,19 +61,11 @@ const Avatar = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _OkuAvatarProps = MergeProps - -type InstanceAvatarType = InstanceTypeRef - -const OkuAvatar = Avatar as typeof Avatar & (new () => { $props: _OkuAvatarProps }) - -export { - OkuAvatar, - createAvatarScope, -} +export const OkuAvatar = avatar as typeof avatar & +(new () => { + $props: ScopeAvatar> +}) export type { AvatarProps, - AvatarElement, - InstanceAvatarType, } diff --git a/packages/components/avatar/src/avatarFallback.ts b/packages/components/avatar/src/avatarFallback.ts index 0e8f76f43..641f9799b 100644 --- a/packages/components/avatar/src/avatarFallback.ts +++ b/packages/components/avatar/src/avatarFallback.ts @@ -1,40 +1,45 @@ -import { defineComponent, h, onMounted, ref, watchEffect } from 'vue' -import type { ElementType, IPrimitiveProps, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { Primitive } from '@oku-ui/primitive' -import { ScopePropObject } from '@oku-ui/provide' +import { defineComponent, h, onMounted, ref, toRef, watchEffect } from 'vue' +import type { ElementType, PrimitiveProps } from '@oku-ui/primitive' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import { useForwardRef } from '@oku-ui/use-composable' import { useAvatarInject } from './avatar' +import type { ScopeAvatar } from './utils' +import { scopeAvatarProps } from './utils' const FALLBACK_NAME = 'OkuAvatarFallback' -type AvatarFallbackElement = ElementType<'span'> -export type _AvatarFalbackEl = HTMLSpanElement +export type AvatarFallbackIntrinsicElement = ElementType<'span'> +export type AvatarFalbackElement = HTMLSpanElement -interface AvatarFallbackProps extends IPrimitiveProps { +interface AvatarFallbackProps extends PrimitiveProps { delayMs?: number } -const AvatarFallback = defineComponent({ +const avatarFallbackProps = { + delayMs: { + type: Number, + required: false, + }, +} + +const avatarFallback = defineComponent({ name: FALLBACK_NAME, inheritAttrs: false, props: { - delayMs: { - type: Number, - required: false, - }, - scopeAvatar: { - ...ScopePropObject, - }, + ...avatarFallbackProps, + ...scopeAvatarProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { - const { ...fallbackProps } = attrs as AvatarFallbackProps - const provide = useAvatarInject(FALLBACK_NAME, props.scopeAvatar) - const canRender = ref(props.delayMs === undefined) + const delayMs = toRef(props, 'delayMs') + const { ...fallbackAttrs } = attrs as AvatarFallbackIntrinsicElement + const provide = useAvatarInject(FALLBACK_NAME, props.scopeOkuAvatar) + const canRender = ref(delayMs.value === undefined) const forwardedRef = useForwardRef() onMounted(() => { - if (props.delayMs === undefined) + if (delayMs.value === undefined) canRender.value = true else canRender.value = false @@ -42,10 +47,10 @@ const AvatarFallback = defineComponent({ onMounted(() => { watchEffect(() => { - if (props.delayMs !== undefined) { + if (delayMs.value !== undefined) { const timerID = window.setTimeout(() => { canRender.value = true - }, props.delayMs) + }, delayMs.value) return () => window.clearTimeout(timerID) } }) @@ -55,8 +60,9 @@ const AvatarFallback = defineComponent({ return (canRender.value && (provide.imageLoadingStatus !== 'loaded')) ? h( Primitive.span, { - ...fallbackProps, + ...fallbackAttrs, ref: forwardedRef, + asChild: props.asChild, }, { default: () => slots.default?.(), @@ -70,18 +76,11 @@ const AvatarFallback = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _OkuAvatarFallbackProps = MergeProps - -type InstanceAvatarFallbackType = InstanceTypeRef - -const OkuAvatarFallback = AvatarFallback as typeof AvatarFallback & (new () => { $props: _OkuAvatarFallbackProps }) - -export { - OkuAvatarFallback, -} +export const OkuAvatarFallback = avatarFallback as typeof avatarFallback & +(new () => { + $props: ScopeAvatar> +}) export type { AvatarFallbackProps, - AvatarFallbackElement, - InstanceAvatarFallbackType, } diff --git a/packages/components/avatar/src/avatarImage.ts b/packages/components/avatar/src/avatarImage.ts index 1a1532877..c9594379c 100644 --- a/packages/components/avatar/src/avatarImage.ts +++ b/packages/components/avatar/src/avatarImage.ts @@ -1,45 +1,47 @@ import type { PropType } from 'vue' -import { defineComponent, h, onMounted, toRefs, watch } from 'vue' -import type { ElementType, IPrimitiveProps, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { Primitive } from '@oku-ui/primitive' +import { defineComponent, h, onMounted, toRef, watch } from 'vue' +import type { ElementType, PrimitiveProps } from '@oku-ui/primitive' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import type { Scope } from '@oku-ui/provide' import { useCallbackRef, useForwardRef } from '@oku-ui/use-composable' -import type { ImageLoadingStatus } from './utils' -import { useImageLoadingStatus } from './utils' +import type { ImageLoadingStatus, ScopeAvatar } from './utils' +import { scopeAvatarProps, useImageLoadingStatus } from './utils' import { useAvatarInject } from './avatar' -const IMAGE_NAME = 'AvatarImage' +const IMAGE_NAME = 'OkuAvatarImage' -type AvatarImageElement = ElementType<'img'> -export type _AvatarImageEl = HTMLImageElement +export type AvatarImageIntrinsicElement = ElementType<'img'> +export type AvatarImageElement = HTMLImageElement -interface AvatarImageProps extends IPrimitiveProps { +interface AvatarImageProps extends PrimitiveProps { onLoadingStatusChange?: (status: ImageLoadingStatus) => void scopeAvatar?: Scope } -const AvatarImage = defineComponent({ +const avatarImageProps = { + onLoadingStatusChange: { + type: Function as unknown as PropType<(status: ImageLoadingStatus) => void>, + required: false, + default: () => { }, + }, + src: { + type: String, + required: true, + }, +} + +const avatarImage = defineComponent({ name: IMAGE_NAME, inheritAttrs: false, props: { - onLoadingStatusChange: { - type: Function as unknown as PropType<(status: ImageLoadingStatus) => void>, - required: false, - default: () => {}, - }, - scopeAvatar: { - type: Object as unknown as PropType, - required: false, - }, - src: { - type: String, - required: true, - }, + ...avatarImageProps, + ...scopeAvatarProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { - const { src } = toRefs(props) - const { ...imageProps } = attrs as AvatarImageElement - const inject = useAvatarInject(IMAGE_NAME, props.scopeAvatar) + const src = toRef(props, 'src') + const { ...imageAttrs } = attrs as AvatarImageIntrinsicElement + const inject = useAvatarInject(IMAGE_NAME, props.scopeOkuAvatar) const forwardedRef = useForwardRef() @@ -63,7 +65,8 @@ const AvatarImage = defineComponent({ const originalReturn = () => imageLoadingStatus.value === 'loaded' ? h( Primitive.img, { - ...imageProps, + asChild: props.asChild, + ...imageAttrs, src: src.value, ref: forwardedRef, }, @@ -78,18 +81,11 @@ const AvatarImage = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _OkuAvatarImageProps = MergeProps - -type InstanceAvatarImageType = InstanceTypeRef - -const OkuAvatarImage = AvatarImage as typeof AvatarImage & (new () => { $props: _OkuAvatarImageProps }) - -export { - OkuAvatarImage, -} +export const OkuAvatarImage = avatarImage as typeof avatarImage & +(new () => { + $props: ScopeAvatar> +}) export type { AvatarImageProps, - AvatarImageElement, - InstanceAvatarImageType, } diff --git a/packages/components/avatar/src/index.ts b/packages/components/avatar/src/index.ts index 926eeeda1..7097c2784 100644 --- a/packages/components/avatar/src/index.ts +++ b/packages/components/avatar/src/index.ts @@ -14,20 +14,17 @@ export { export type { AvatarProps, AvatarElement, - InstanceAvatarType, - _AvatarEl, + AvatarIntrinsicElement, } from './avatar' export type { AvatarFallbackProps, - InstanceAvatarFallbackType, - AvatarFallbackElement, - _AvatarFalbackEl, + AvatarFalbackElement, + AvatarFallbackIntrinsicElement, } from './avatarFallback' export type { AvatarImageProps, AvatarImageElement, - InstanceAvatarImageType, - _AvatarImageEl, + AvatarImageIntrinsicElement, } from './avatarImage' diff --git a/packages/components/avatar/src/stories/AvatarDemo.vue b/packages/components/avatar/src/stories/AvatarDemo.vue index 35c5496ec..deeb5635b 100644 --- a/packages/components/avatar/src/stories/AvatarDemo.vue +++ b/packages/components/avatar/src/stories/AvatarDemo.vue @@ -1,9 +1,7 @@ - diff --git a/packages/components/popper/src/index.ts b/packages/components/popper/src/index.ts index 1ee690ab1..57f434975 100644 --- a/packages/components/popper/src/index.ts +++ b/packages/components/popper/src/index.ts @@ -13,8 +13,8 @@ export { export type { PopperAnchorProps, - InstancePopperAnchorType, - _PopperAnchorEl, + PopperAnchorElement, + PopperAnchorIntrinsicElement, } from './popperAnchor' export { @@ -23,8 +23,8 @@ export { export type { PopperContentProps, - InstancePopperContentType, - _PopperContentEl, + PopperContentElement, + PopperContentIntrinsicElement, } from './popperContent' export { @@ -33,5 +33,6 @@ export { export type { PopperArrowProps, - InstancePopperArrowType, + PopperArrowElement, + PopperArrowIntrinsicElement, } from './popperArrow' diff --git a/packages/components/popper/src/popper.ts b/packages/components/popper/src/popper.ts index 4aec0504d..cfb1d99ce 100644 --- a/packages/components/popper/src/popper.ts +++ b/packages/components/popper/src/popper.ts @@ -2,43 +2,37 @@ import type { Ref } from 'vue' import { defineComponent, ref } from 'vue' import type { Measurable } from '@oku-ui/utils' -import type { Scope } from '@oku-ui/provide' -import { ScopePropObject, createProvideScope } from '@oku-ui/provide' +import { createProvideScope } from '@oku-ui/provide' +import type { ScopePopper } from './utils' +import { scopePopperProps } from './utils' -/* ------------------------------------------------------------------------------------------------- - * Popper - * ----------------------------------------------------------------------------------------------- */ - -const POPPER_NAME = 'Popper' +const POPPER_NAME = 'OkuPopper' export const [createPopperProvider, createPopperScope] = createProvideScope(POPPER_NAME) -export type PopperInjectValue = { +export type PopperProvideValue = { anchor: Ref onAnchorChange(anchor: Measurable | null): void } -export const [PopperProvider, usePopperInject] - = createPopperProvider(POPPER_NAME) +export const [popperProvider, usePopperInject] + = createPopperProvider(POPPER_NAME) interface PopperProps { - scopeCheckbox?: Scope } const Popper = defineComponent({ name: POPPER_NAME, inheritAttrs: false, props: { - scopeCheckbox: { - ...ScopePropObject, - }, + ...scopePopperProps, }, setup(props, { slots }) { const anchor = ref(null) - PopperProvider({ - scope: props.scopeCheckbox, + popperProvider({ + scope: props.scopeOkuPopper, anchor, onAnchorChange(_anchor: Measurable | null) { anchor.value = _anchor @@ -51,11 +45,7 @@ const Popper = defineComponent({ }, }) -type _PopperProps = PopperProps - -const OkuPopper = Popper as typeof Popper & -(new () => { $props: _PopperProps }) - -export { OkuPopper } +export const OkuPopper = Popper as typeof Popper & +(new () => { $props: ScopePopper }) export type { PopperProps } diff --git a/packages/components/popper/src/popperAnchor.ts b/packages/components/popper/src/popperAnchor.ts index 53f81a50b..560821dd9 100644 --- a/packages/components/popper/src/popperAnchor.ts +++ b/packages/components/popper/src/popperAnchor.ts @@ -2,57 +2,58 @@ import type { PropType, Ref } from 'vue' import { defineComponent, h, ref, toRefs, watch } from 'vue' import type { - ComponentPublicInstanceRef, ElementType, - IPrimitiveProps, - InstanceTypeRef, - MergeProps, + PrimitiveProps, } from '@oku-ui/primitive' import type { Measurable } from '@oku-ui/utils' -import { type Scope, ScopePropObject } from '@oku-ui/provide' -import { Primitive, PrimitiveProps } from '@oku-ui/primitive' +import { type Scope } from '@oku-ui/provide' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import { useComposedRefs, useForwardRef } from '@oku-ui/use-composable' import { usePopperInject } from './popper' +import type { ScopePopper } from './utils' +import { scopePopperProps } from './utils' /* ------------------------------------------------------------------------------------------------- * PopperAnchor * ----------------------------------------------------------------------------------------------- */ -const ANCHOR_NAME = 'PopperAnchor' +const ANCHOR_NAME = 'OkuPopperAnchor' -type PopperAnchorElement = ElementType<'div'> -export type _PopperAnchorEl = HTMLDivElement +export type PopperAnchorIntrinsicElement = ElementType<'div'> +export type PopperAnchorElement = HTMLDivElement -interface PopperAnchorProps extends IPrimitiveProps { +interface PopperAnchorProps extends PrimitiveProps { virtualRef?: Ref scopeCheckbox?: Scope } -const PopperAnchor = defineComponent({ +const popperAnchorProps = { + virtualRef: { + type: Object as unknown as PropType>, + required: false, + default: undefined, + }, +} + +const popperAnchor = defineComponent({ name: ANCHOR_NAME, inheritAttrs: false, props: { - virtualRef: { - type: Object as unknown as PropType>, - required: false, - default: undefined, - }, - scopeCheckbox: { - ...ScopePropObject, - }, - ...PrimitiveProps, + ...scopePopperProps, + ...popperAnchorProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { const { virtualRef } = toRefs(props) - const { ...attrsAnchor } = attrs as PopperAnchorElement - const inject = usePopperInject(ANCHOR_NAME, props.scopeCheckbox) + const { ...attrsAnchor } = attrs as PopperAnchorIntrinsicElement + const inject = usePopperInject(ANCHOR_NAME, props.scopeOkuPopper) - const _ref = ref | null>(null) + const _ref = ref(null) const composedRefs = useComposedRefs(_ref, useForwardRef()) watch(_ref, () => { inject.anchor.value - = virtualRef.value?.value || (_ref.value?.$el as Measurable) + = virtualRef.value?.value || (_ref.value as Measurable) }) const originalReturn = () => @@ -74,12 +75,9 @@ const PopperAnchor = defineComponent({ }, }) -type _PopperAnchor = MergeProps -type InstancePopperAnchorType = InstanceTypeRef - -const OkuPopperAnchor = PopperAnchor as typeof PopperAnchor & -(new () => { $props: _PopperAnchor }) - -export { OkuPopperAnchor } +export const OkuPopperAnchor = popperAnchor as typeof popperAnchor & +(new () => { + $props: ScopePopper> +}) -export type { PopperAnchorProps, PopperAnchorElement, InstancePopperAnchorType } +export type { PopperAnchorProps } diff --git a/packages/components/popper/src/popperArrow.ts b/packages/components/popper/src/popperArrow.ts index da1dc94ab..c049e2863 100644 --- a/packages/components/popper/src/popperArrow.ts +++ b/packages/components/popper/src/popperArrow.ts @@ -1,19 +1,18 @@ import { computed, defineComponent, h } from 'vue' -import type { - ElementType, - IPrimitiveProps, - InstanceTypeRef, - MergeProps, +import { + type ElementType, + type PrimitiveProps, + primitiveProps, } from '@oku-ui/primitive' -import { type Scope, ScopePropObject } from '@oku-ui/provide' -import type { ArrowProps, _ArrowEl } from '@oku-ui/arrow' +import { type Scope } from '@oku-ui/provide' +import type { ArrowProps } from '@oku-ui/arrow' import { OkuArrow } from '@oku-ui/arrow' import { useForwardRef } from '@oku-ui/use-composable' -import type { Side } from './utils' +import { type ScopePopper, type Side, scopePopperProps } from './utils' import { usePopperContentInject } from './popperContent' -const ARROW_NAME = 'PopperArrow' +const ARROW_NAME = 'OkuPopperArrow' const OPPOSITE_SIDE: Record = { top: 'bottom', @@ -22,21 +21,22 @@ const OPPOSITE_SIDE: Record = { left: 'right', } -type PopperArrowElement = ElementType<'svg'> -interface PopperArrowProps extends IPrimitiveProps, ArrowProps { +export type PopperArrowIntrinsicElement = ElementType<'svg'> +export type PopperArrowElement = SVGSVGElement + +interface PopperArrowProps extends PrimitiveProps, ArrowProps { scopePopper?: Scope } -const PopperArrow = defineComponent({ +const popperArrow = defineComponent({ name: ARROW_NAME, props: { - scopePopper: { - ...ScopePropObject, - }, + ...scopePopperProps, + ...primitiveProps, }, setup(props, { attrs }) { - const { ...attrsElement } = attrs as PopperArrowElement - const contentInject = usePopperContentInject(ARROW_NAME, props.scopePopper) + const { ...attrsElement } = attrs as PopperArrowIntrinsicElement + const contentInject = usePopperContentInject(ARROW_NAME, props.scopeOkuPopper) const baseSide = computed(() => { return OPPOSITE_SIDE[contentInject.placedSide.value] }) @@ -75,7 +75,7 @@ const PopperArrow = defineComponent({ }, [ h(OkuArrow, { - ...attrsElement, + ...attrsElement as any, ref: forwardedRef, style: { ...(attrsElement.style as any), @@ -88,12 +88,10 @@ const PopperArrow = defineComponent({ }, }) -type _PopperArrow = MergeProps -type InstancePopperArrowType = InstanceTypeRef - -const OkuPopperArrow = PopperArrow as typeof PopperArrow & -(new () => { $props: _PopperArrow }) - -export { OkuPopperArrow } +// TODO: https://github.com/vuejs/core/pull/7444 after delete +export const OkuPopperArrow = popperArrow as typeof popperArrow +& (new () => { + $props: ScopePopper> +}) -export type { PopperArrowProps, InstancePopperArrowType } +export type { PopperArrowProps } diff --git a/packages/components/popper/src/popperContent.ts b/packages/components/popper/src/popperContent.ts index b58731087..e6cffedf9 100644 --- a/packages/components/popper/src/popperContent.ts +++ b/packages/components/popper/src/popperContent.ts @@ -1,9 +1,8 @@ import type { PropType, Ref, StyleValue } from 'vue' import { computed, defineComponent, h, onMounted, ref, toRefs, watch, watchEffect } from 'vue' -import { Primitive, PrimitiveProps } from '@oku-ui/primitive' -import type { ComponentPublicInstanceRef, ElementType, IPrimitiveProps, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { ScopePropObject } from '@oku-ui/provide' +import { Primitive, primitiveProps } from '@oku-ui/primitive' +import type { ElementType, PrimitiveProps } from '@oku-ui/primitive' import { computedEager, useCallbackRef, useComposedRefs, useForwardRef, useSize } from '@oku-ui/use-composable' import { autoUpdate, flip, arrow as floatingUIarrow, hide, limitShift, offset, shift, size, useFloating } from '@floating-ui/vue' import type { @@ -12,12 +11,12 @@ import type { Padding, Placement, } from '@floating-ui/vue' -import type { Align, Side } from './utils' -import { ALIGN_OPTIONS, SIDE_OPTIONS, getSideAndAlignFromPlacement, isDefined, isNotNull, transformOrigin } from './utils' -import type { PopperInjectValue } from './popper' +import type { Align, ScopePopper, Side } from './utils' +import { ALIGN_OPTIONS, SIDE_OPTIONS, getSideAndAlignFromPlacement, isDefined, isNotNull, scopePopperProps, transformOrigin } from './utils' +import type { PopperProvideValue } from './popper' import { createPopperProvider, usePopperInject } from './popper' -const CONTENT_NAME = 'PopperContent' +const CONTENT_NAME = 'OkuPopperContent' type PopperContentContextValue = { placedSide: Ref @@ -27,16 +26,16 @@ type PopperContentContextValue = { shouldHideArrow: Ref x?: Ref y?: Ref -} & PopperInjectValue +} & PopperProvideValue -export const [PopperContentProvider, usePopperContentInject] = createPopperProvider(CONTENT_NAME) +export const [popperContentProvider, usePopperContentInject] = createPopperProvider(CONTENT_NAME) type Boundary = Element | null -type PopperContentElement = ElementType<'div'> -export type _PopperContentEl = HTMLDivElement +export type PopperContentIntrinsicElement = ElementType<'div'> +export type PopperContentElement = HTMLDivElement -interface PopperContentProps extends IPrimitiveProps { +interface PopperContentProps extends PrimitiveProps { side?: Side sideOffset?: number align?: Align @@ -51,76 +50,78 @@ interface PopperContentProps extends IPrimitiveProps { onPlaced?: () => void } +const popperContentProps = { + side: { + type: String as unknown as PropType, + required: false, + default: 'bottom', + validator: (value: Side) => SIDE_OPTIONS.includes(value), + }, + sideOffset: { + type: Number, + required: false, + default: 0, + }, + align: { + type: String as unknown as PropType, + required: false, + default: 'center', + validator: (value: Align) => ALIGN_OPTIONS.includes(value), + }, + alignOffset: { + type: Number, + required: false, + default: 0, + }, + arrowPadding: { + type: Number, + required: false, + default: 0, + }, + avoidCollisions: { + type: Boolean, + required: false, + default: true, + }, + collisionBoundary: { + type: [Object, Array] as unknown as PropType, + required: false, + default: () => [], + }, + collisionPadding: { + type: [Number, Object] as unknown as PropType, + required: false, + default: 0, + }, + sticky: { + type: String as unknown as PropType<'partial' | 'always'>, + required: false, + default: 'partial', + }, + hideWhenDetached: { + type: Boolean, + required: false, + default: false, + }, + updatePositionStrategy: { + type: String as unknown as PropType<'optimized' | 'always'>, + required: false, + default: 'optimized', + }, + onPlaced: { + type: Function as unknown as PropType<() => void>, + required: false, + default: undefined, + }, +} + const PopperContent = defineComponent({ name: CONTENT_NAME, inheritAttrs: false, props: { - side: { - type: String as unknown as PropType, - required: false, - default: 'bottom', - validator: (value: Side) => SIDE_OPTIONS.includes(value), - }, - sideOffset: { - type: Number, - required: false, - default: 0, - }, - align: { - type: String as unknown as PropType, - required: false, - default: 'center', - validator: (value: Align) => ALIGN_OPTIONS.includes(value), - }, - alignOffset: { - type: Number, - required: false, - default: 0, - }, - arrowPadding: { - type: Number, - required: false, - default: 0, - }, - avoidCollisions: { - type: Boolean, - required: false, - default: true, - }, - collisionBoundary: { - type: [Object, Array] as unknown as PropType, - required: false, - default: () => [], - }, - collisionPadding: { - type: [Number, Object] as unknown as PropType, - required: false, - default: 0, - }, - sticky: { - type: String as unknown as PropType<'partial' | 'always'>, - required: false, - default: 'partial', - }, - hideWhenDetached: { - type: Boolean, - required: false, - default: false, - }, - updatePositionStrategy: { - type: String as unknown as PropType<'optimized' | 'always'>, - required: false, - default: 'optimized', - }, - onPlaced: { - type: Function as unknown as PropType<() => void>, - required: false, - default: undefined, - }, - scopePopper: { - ...ScopePropObject, - }, - ...PrimitiveProps, + ...popperContentProps, + ...scopePopperProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { const { @@ -138,11 +139,11 @@ const PopperContent = defineComponent({ onPlaced, } = toRefs(props) - const { ...attrsElement } = attrs as PopperContentElement + const { ...attrsElement } = attrs as PopperContentIntrinsicElement - const inject = usePopperInject(CONTENT_NAME, props.scopePopper) + const inject = usePopperInject(CONTENT_NAME, props.scopeOkuPopper) - const content = ref | null>(null) + const content = ref(null) const composedRefs = useComposedRefs(content, useForwardRef()) const arrow = ref(null) @@ -249,13 +250,13 @@ const PopperContent = defineComponent({ watchEffect(() => { if (content.value) - contentZIndex.value = window.getComputedStyle(content.value.$el).zIndex + contentZIndex.value = window.getComputedStyle(content.value).zIndex }) - PopperContentProvider({ + popperContentProvider({ arrowX, arrowY, - scope: props.scopePopper, + scope: props.scopeOkuPopper, shouldHideArrow: cannotCenterArrow, onAnchorChange(anchor: HTMLElement | null) { arrow.value = anchor @@ -311,16 +312,12 @@ const PopperContent = defineComponent({ }, }) -type _PopperContent = MergeProps -type InstancePopperContentType = InstanceTypeRef - -const OkuPopperContent = PopperContent as typeof PopperContent & (new () => { $props: _PopperContent }) - -export { - OkuPopperContent, -} +// TODO: https://github.com/vuejs/core/pull/7444 after delete +export const OkuPopperContent = PopperContent as typeof PopperContent +& (new () => { + $props: ScopePopper> +}) export type { PopperContentProps, - InstancePopperContentType, } diff --git a/packages/components/popper/src/utils.ts b/packages/components/popper/src/utils.ts index 24de03429..98acef8bd 100644 --- a/packages/components/popper/src/utils.ts +++ b/packages/components/popper/src/utils.ts @@ -1,4 +1,14 @@ import type { Middleware, Placement } from '@floating-ui/vue' +import type { Scope } from '@oku-ui/provide' +import { ScopePropObject } from '@oku-ui/provide' + +export type ScopePopper = T & { scopeOkuPopper?: Scope } + +export const scopePopperProps = { + scopeOkuPopper: { + ...ScopePropObject, + }, +} export const SIDE_OPTIONS = ['top', 'right', 'bottom', 'left'] as const export const ALIGN_OPTIONS = ['start', 'center', 'end'] as const diff --git a/packages/components/presence/src/presence.ts b/packages/components/presence/src/presence.ts index 958093b2e..79b862fc6 100644 --- a/packages/components/presence/src/presence.ts +++ b/packages/components/presence/src/presence.ts @@ -6,16 +6,17 @@ interface PresenceProps { present: boolean } +const presenceProps = { + present: Boolean, +} + const NAME = 'OkuPresence' const presence = defineComponent({ name: NAME, inheritAttrs: false, props: { - present: { - type: Boolean, - default: false, - }, + ...presenceProps, }, setup(props, { slots }) { const { present } = toRefs(props) @@ -25,10 +26,10 @@ const presence = defineComponent({ const composedRefs = useComposedRefs(presenceRef, forwardedRef) return () => { - const ddd = slots.default?.({ + const slot = slots.default?.({ isPresent, }) - const [child] = ddd ?? [] + const [child] = slot ?? [] return isPresent.value ? h(child, { diff --git a/packages/components/progress/src/index.ts b/packages/components/progress/src/index.ts index bbef17f9c..a1081dd3b 100644 --- a/packages/components/progress/src/index.ts +++ b/packages/components/progress/src/index.ts @@ -1,11 +1,10 @@ export { OkuProgress, createProgressScope } from './progress' -export type { ProgressProps, ProgressElement, InstanceProgressType } from './progress' +export type { ProgressProps, ProgressElement } from './progress' export { OkuProgressIndicator } from './progressIndicator' export type { - InstanceProgressIndicatorType, ProgressIndicatorElement, ProgressIndicatorProps, } from './progressIndicator' diff --git a/packages/components/progress/src/progress.ts b/packages/components/progress/src/progress.ts index 98afbd914..29987685c 100644 --- a/packages/components/progress/src/progress.ts +++ b/packages/components/progress/src/progress.ts @@ -1,10 +1,11 @@ -import type { ElementType, InstanceTypeRef, MergeProps } from '@oku-ui/primitive' -import { Primitive, PrimitiveProps } from '@oku-ui/primitive' +import type { ElementType } from '@oku-ui/primitive' +import { Primitive, primitiveProps } from '@oku-ui/primitive' import type { Scope } from '@oku-ui/provide' -import { ScopePropObject, createProvideScope } from '@oku-ui/provide' -import type { ComputedRef, PropType } from 'vue' +import { createProvideScope } from '@oku-ui/provide' +import type { PropType, Ref } from 'vue' import { computed, defineComponent, h, toRefs } from 'vue' import { useForwardRef } from '@oku-ui/use-composable' +import type { ScopeProgress } from './utils' import { defaultGetValueLabel, getInvalidMaxError, @@ -13,19 +14,17 @@ import { isNumber, isValidMaxNumber, isValidValueNumber, + scopeProgressProps, } from './utils' import { DEFAULT_MAX, PROGRESS_NAME } from './constants' -import type { ProgressIndicatorProps } from '.' -// ---------- Progress ---------- // - -type ProgressContextValue = { - value: ComputedRef | null - max: ComputedRef +type ProgressInjectValue = { + value: Ref | null + max: Ref } -type ProgressElement = ElementType<'div'> -export type _ProgressEl = HTMLDivElement +export type ProgressIntrinsicElement = ElementType<'div'> +export type ProgressElement = HTMLDivElement interface ProgressProps { value?: number | null @@ -34,36 +33,37 @@ interface ProgressProps { scopeProgress?: Scope } -const [createProgressContext, createProgressScope] +export const [createProgressContext, createProgressScope] = createProvideScope(PROGRESS_NAME) -const [progressProvider, useProgressContext] - = createProgressContext(PROGRESS_NAME) +export const [progressProvider, useProgressInject] + = createProgressContext(PROGRESS_NAME) + +const progressProps = { + value: { + type: [Number, null] as PropType, + }, + max: { + type: Number, + default: DEFAULT_MAX, + }, + getValueLabel: { + type: Function as PropType<(value: number, max: number) => string>, + default: defaultGetValueLabel, + }, +} -// ---component--- -const Progress = defineComponent({ +const progress = defineComponent({ name: PROGRESS_NAME, inheritAttrs: false, props: { - value: { - type: [Number, null] as PropType, - }, - max: { - type: Number, - default: DEFAULT_MAX, - }, - getValueLabel: { - type: Function as PropType<(value: number, max: number) => string>, - default: defaultGetValueLabel, - }, - scopeProgress: { - ...ScopePropObject, - }, - ...PrimitiveProps, + ...progressProps, + ...scopeProgressProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { - const { value, max, getValueLabel, scopeProgress } = toRefs(props) - const { ...progressProps } = attrs as ProgressElement + const { value, max, getValueLabel, scopeOkuProgress } = toRefs(props) + const { ...progressProps } = attrs as ProgressIntrinsicElement const forwardedRef = useForwardRef() @@ -87,7 +87,7 @@ const Progress = defineComponent({ ) progressProvider({ - scope: scopeProgress.value, + scope: scopeOkuProgress.value, value: valueProp, max: maxProp, }) @@ -122,13 +122,9 @@ const Progress = defineComponent({ }) // TODO: https://github.com/vuejs/core/pull/7444 after delete -type _OkuProgressProps = MergeProps - -type InstanceProgressType = InstanceTypeRef - -const OkuProgress = Progress as typeof Progress & -(new () => { $props: _OkuProgressProps }) - -export { createProgressScope, OkuProgress, useProgressContext } +export const OkuProgress = progress as typeof progress & +(new () => { + $props: ScopeProgress> +}) -export type { ProgressProps, ProgressElement, InstanceProgressType } +export type { ProgressProps } diff --git a/packages/components/progress/src/progressIndicator.ts b/packages/components/progress/src/progressIndicator.ts index a851949d2..47670efed 100644 --- a/packages/components/progress/src/progressIndicator.ts +++ b/packages/components/progress/src/progressIndicator.ts @@ -1,37 +1,36 @@ import { defineComponent, h } from 'vue' -import type { - ElementType, - IPrimitiveProps, - InstanceTypeRef, - MergeProps, +import { + type ElementType, + type PrimitiveProps, + primitiveProps, } from '@oku-ui/primitive' -import { type Scope, ScopePropObject } from '@oku-ui/provide' +import { type Scope } from '@oku-ui/provide' import { useForwardRef } from '@oku-ui/use-composable' -import { getProgressState } from './utils' -import { useProgressContext } from './progress' +import type { ScopeProgress } from './utils' +import { getProgressState, scopeProgressProps } from './utils' +import { useProgressInject } from './progress' import { INDICATOR_NAME } from './constants' -type ProgressIndicatorElement = ElementType<'div'> -export type _ProgressIndicatorEl = HTMLDivElement +type ProgressIndicatorElementIntrinsicElement = ElementType<'div'> +export type ProgressIndicatorElement = HTMLDivElement -interface ProgressIndicatorProps extends IPrimitiveProps { +interface ProgressIndicatorProps extends PrimitiveProps { scopeProgress?: Scope } -const ProgressIndicator = defineComponent({ +const progressIndicator = defineComponent({ name: INDICATOR_NAME, inheritAttrs: true, props: { - scopeProgress: { - ...ScopePropObject, - }, + ...scopeProgressProps, + ...primitiveProps, }, setup(props, { attrs, slots }) { - const { ...indicatorProps } = attrs as ProgressIndicatorProps + const { ...indicatorAttrs } = attrs as ProgressIndicatorElementIntrinsicElement const forwardedRef = useForwardRef() - const context = useProgressContext(INDICATOR_NAME, props.scopeProgress) + const context = useProgressInject(INDICATOR_NAME, props.scopeOkuProgress) const originalReturn = () => h( @@ -43,7 +42,7 @@ const ProgressIndicator = defineComponent({ ), 'data-value': context.value?.value ?? undefined, 'data-max': context.max.value, - ...indicatorProps, + ...indicatorAttrs, 'ref': forwardedRef, }, { @@ -55,19 +54,10 @@ const ProgressIndicator = defineComponent({ }, }) -type _OkuProgressIndicatorProps = MergeProps< - ProgressIndicatorProps, - ProgressIndicatorElement -> -type InstanceProgressIndicatorType = InstanceTypeRef - -const OkuProgressIndicator = ProgressIndicator as typeof ProgressIndicator & -(new () => { $props: _OkuProgressIndicatorProps }) - -export { OkuProgressIndicator } +// TODO: https://github.com/vuejs/core/pull/7444 after delete +export const OkuProgressIndicator = progressIndicator as typeof progressIndicator & +(new () => { + $props: ScopeProgress> +}) -export type { - ProgressIndicatorProps, - ProgressIndicatorElement, - InstanceProgressIndicatorType, -} +export type { ProgressIndicatorProps } diff --git a/packages/components/progress/src/stories/ProgressDemo.vue b/packages/components/progress/src/stories/ProgressDemo.vue index 7b2d05349..782d8c46a 100644 --- a/packages/components/progress/src/stories/ProgressDemo.vue +++ b/packages/components/progress/src/stories/ProgressDemo.vue @@ -1,10 +1,8 @@ -