@teammodlr/ui-kit 2.1.78 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/dialog/Dialog.vue.d.ts +1 -1
- package/lib/components/dropdown/Dropdown.vue.d.ts +14 -9
- package/lib/components/dropdown/DropdownTrigger.vue.d.ts +11 -0
- package/lib/components/messageprovider/Message.vue.d.ts +1 -1
- package/lib/components/modal/Modal.vue.d.ts +1 -1
- package/lib/components/primative/index.d.ts +2 -0
- package/lib/components/primative/primitive.d.ts +30 -0
- package/lib/components/primative/slot.d.ts +5 -0
- package/lib/components/tooltip/Tooltip.vue.d.ts +12 -6
- package/lib/components/tooltip/TooltipTrigger.vue.d.ts +11 -0
- package/lib/index.cjs.js +7 -7
- package/lib/index.es.js +2675 -2542
- package/lib/utils/renderSlotFragments.d.ts +2 -0
- package/lib/utils/useForwardExpose.d.ts +6 -0
- package/package.json +1 -1
- package/src/components/button/Button.vue +1 -2
- package/src/components/dialog/Dialog.vue +4 -2
- package/src/components/dialogprovider/examples/basic.vue +54 -54
- package/src/components/dialogprovider/examples/index.stories.ts +26 -26
- package/src/components/dropdown/Dropdown.vue +28 -7
- package/src/components/dropdown/DropdownTrigger.vue +20 -0
- package/src/components/primative/examples/as-child.vue +13 -0
- package/src/components/primative/examples/as.vue +13 -0
- package/src/components/primative/examples/index.stories.ts +12 -0
- package/src/components/primative/examples/index.ts +2 -0
- package/src/components/primative/index.ts +2 -0
- package/src/components/primative/primitive.ts +56 -0
- package/src/components/primative/slot.ts +45 -0
- package/src/components/tooltip/Tooltip.vue +26 -8
- package/src/components/tooltip/TooltipTrigger.vue +20 -0
- package/src/components/tooltip/examples/basic.vue +1 -1
- package/src/utils/renderSlotFragments.ts +15 -0
- package/src/utils/useForwardExpose.ts +65 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// reference: https://github.com/vuejs/rfcs/issues/258#issuecomment-1068697672
|
|
2
|
+
import {unrefElement} from '@vueuse/core'
|
|
3
|
+
import {type ComponentPublicInstance, computed, getCurrentInstance, ref} from 'vue'
|
|
4
|
+
|
|
5
|
+
export function useForwardExpose() {
|
|
6
|
+
const instance = getCurrentInstance()!
|
|
7
|
+
|
|
8
|
+
const currentRef = ref<Element | ComponentPublicInstance | null>()
|
|
9
|
+
const currentElement = computed<HTMLElement>(() => {
|
|
10
|
+
// $el could be text/comment for non-single root normal or text root, thus we retrieve the nextElementSibling
|
|
11
|
+
// @ts-expect-error ignore ts error
|
|
12
|
+
return ['#text', '#comment'].includes(currentRef.value?.$el.nodeName) ? currentRef.value?.$el.nextElementSibling : unrefElement(currentRef)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Do give us credit if you reference our code :D
|
|
16
|
+
// localExpose should only be assigned once else will create infinite loop
|
|
17
|
+
const localExpose: Record<string, any> | null = Object.assign({}, instance.exposed)
|
|
18
|
+
const ret: Record<string, any> = {}
|
|
19
|
+
|
|
20
|
+
// retrieve props for current instance
|
|
21
|
+
for (const key in instance.props) {
|
|
22
|
+
Object.defineProperty(ret, key, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
get: () => instance.props[key],
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// retrieve default exposed value
|
|
30
|
+
if (Object.keys(localExpose).length > 0) {
|
|
31
|
+
for (const key in localExpose) {
|
|
32
|
+
Object.defineProperty(ret, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
get: () => localExpose![key],
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// retrieve original first root element
|
|
41
|
+
Object.defineProperty(ret, '$el', {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
get: () => instance.vnode.el,
|
|
45
|
+
})
|
|
46
|
+
instance.exposed = ret
|
|
47
|
+
|
|
48
|
+
function forwardRef(ref: Element | ComponentPublicInstance | null) {
|
|
49
|
+
currentRef.value = ref
|
|
50
|
+
|
|
51
|
+
if (ref instanceof Element || !ref)
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
// retrieve the forwarded element
|
|
55
|
+
Object.defineProperty(ret, '$el', {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
get: () => ref.$el,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
instance.exposed = ret
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {forwardRef, currentRef, currentElement}
|
|
65
|
+
}
|