Skip to content

Commit

Permalink
feat(core): 添加ReturnWidget类型定义
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwangyihao committed Oct 5, 2024
1 parent 7e6425a commit c4e786d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/core/src/widget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Reactive, Ref } from 'vue'
import { getCurrentInstance, inject, nextTick, onMounted, provide, reactive, ref, useSlots } from 'vue'
import type { Reactive } from 'vue'
import { getCurrentInstance, inject, onMounted, provide, reactive, ref, useSlots } from 'vue'

export interface Range {
x: number
Expand All @@ -16,16 +16,18 @@ export interface Widget {
children?: Widget[]
}

export type ReturnWidget<T extends Widget> = ReturnType<typeof defineWidget<T>>

export function defineWidget<T extends Widget>(props: T, root?: SVGElement): Reactive<T> {
let widget = inject<T>(props.wid as string)
const widgets = inject('child-widgets') as T[]

// const children = reactive([])
// provide('child-widgets', children)

widget ??= {} as T
Object.assign(widget, props)

onMounted(() => {
widget.element = root ?? getCurrentInstance()!.proxy!.$el.parentElement
widget.range = widget.element!.getBoundingClientRect()
Expand All @@ -35,7 +37,7 @@ export function defineWidget<T extends Widget>(props: T, root?: SVGElement): Rea
widgets.push(widget)
}
})

return reactive(widget)
}

Expand Down

0 comments on commit c4e786d

Please sign in to comment.