Skip to content

Commit 831ef28

Browse files
committed
refactor: rename h.ts to useVNodesContainer.ts
1 parent 7949452 commit 831ef28

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

packages/vue-final-modal/src/Modal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { App, CSSProperties, Component, ComponentInternalInstance, Ref } from 'vue'
22
import type { ComponentProps, ComponentSlots } from './Component'
3-
import type { H } from './h'
3+
import type { VNodesContainer } from './useVNodesContainer'
44

55
export type ModalId = number | string | symbol
66
export type StyleValue = string | CSSProperties | (string | CSSProperties)[]
@@ -43,7 +43,7 @@ export type Vfm = {
4343
modals: ComponentInternalInstance[]
4444
openedModals: ComponentInternalInstance[]
4545
openedModalOverlays: ComponentInternalInstance[]
46-
h: H
46+
vNodesContainer: VNodesContainer
4747
get: (modalId: ModalId) => undefined | ComponentInternalInstance
4848
toggle: (modalId: ModalId, show?: boolean) => undefined | Promise<string>
4949
open: (modalId: ModalId) => undefined | Promise<string>

packages/vue-final-modal/src/components/ModalsContainer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { useVfm } from '~/useVfm'
44
export const ModalsContainer = defineComponent({
55
name: 'ModalsContainer',
66
setup() {
7-
const { h } = useVfm()
7+
const { vNodesContainer } = useVfm()
88

99
const uid = Symbol(__DEV__ ? 'ModalsContainer' : '')
10-
const shouldMount = computed(() => uid === h.containers.value?.[0])
10+
const shouldMount = computed(() => uid === vNodesContainer.containers.value?.[0])
1111

12-
h.containers.value.push(uid)
12+
vNodesContainer.containers.value.push(uid)
1313
onBeforeUnmount(() => {
14-
h.containers.value = h.containers.value.filter(i => i !== uid)
14+
vNodesContainer.containers.value = vNodesContainer.containers.value.filter(i => i !== uid)
1515
})
1616

1717
return () => {
1818
if (!shouldMount.value)
1919
return null
20-
return h.vNodes
20+
return vNodesContainer.vNodes
2121
}
2222
},
2323
})

packages/vue-final-modal/src/plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getCurrentInstance, inject, markRaw, ref, shallowReactive } from 'vue'
33
import { vfmSymbol } from './injectionSymbols'
44
import type { ModalExposed, ModalId, Vfm } from './Modal'
55
import { noop } from './utils'
6-
import { createH } from './h'
6+
import { useVNodesContainer } from './useVNodesContainer'
77

88
// eslint-disable-next-line import/no-mutable-exports
99
export let activeVfm: Vfm | undefined
@@ -16,7 +16,7 @@ export const defaultVfm: Vfm = {
1616
modals: [],
1717
openedModals: [],
1818
openedModalOverlays: [],
19-
h: {
19+
vNodesContainer: {
2020
vNodes: [],
2121
containers: ref([]),
2222
push: noop,
@@ -45,7 +45,7 @@ export function createVfm() {
4545
modals,
4646
openedModals,
4747
openedModalOverlays,
48-
h: createH(),
48+
vNodesContainer: useVNodesContainer(),
4949
get(modalId: ModalId) {
5050
return modals.find(modal => getModalExposed(modal)?.value.modalId?.value === modalId)
5151
},

packages/vue-final-modal/src/h.ts renamed to packages/vue-final-modal/src/useVNodesContainer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { Ref, VNode } from 'vue'
22
import { ref, shallowReactive } from 'vue'
33

4-
export type H = {
4+
export type VNodesContainer = {
55
vNodes: VNode[]
66
containers: Ref<symbol[]>
77
push: (vNode: VNode) => void
88
remove: (vNode: VNode) => void
99
}
1010

11-
export function createH(): H {
11+
export function useVNodesContainer(): VNodesContainer {
1212
const vNodes: VNode[] = shallowReactive([])
1313
const containers = ref<symbol[]>([])
1414

@@ -23,11 +23,11 @@ export function createH(): H {
2323
vNodes.splice(index, 1)
2424
}
2525

26-
const _h: H = {
26+
const _vNodesContainer: VNodesContainer = {
2727
vNodes,
2828
containers,
2929
push,
3030
remove,
3131
}
32-
return _h
32+
return _vNodesContainer
3333
}

packages/vue-final-modal/src/useVfmAttrs.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@ import { computed, useAttrs } from 'vue'
33
import type { ComponentEmit, ComponentProps } from './Component'
44
import type { VueFinalModal } from '.'
55

6-
export function pickModalProps(props: Record<string, any>, modalProps: Record<string, any>) {
6+
export function useVfmAttrs<TP extends Component, MP extends Component>(options: {
7+
props: ComponentProps<TP>
8+
modalProps: ComponentProps<MP>
9+
emit?: any
10+
}) {
11+
const { props, modalProps, emit } = options
12+
const bindProps = computed(() => pickModalProps(props, modalProps))
13+
const bindEmits = byPassAllModalEvents(emit)
14+
const attrs = useAttrs()
15+
const vfmAttrs = computed(() => ({
16+
...bindProps.value,
17+
...bindEmits,
18+
...attrs,
19+
}))
20+
21+
return vfmAttrs
22+
}
23+
24+
function pickModalProps(props: Record<string, any>, modalProps: Record<string, any>) {
725
return Object.keys(modalProps).reduce<Record<string, any>>((acc, propName) => {
826
acc[propName] = props?.[propName]
927
return acc
1028
}, {})
1129
}
1230

13-
export function byPassAllModalEvents(emit?: ComponentEmit<typeof VueFinalModal>): ComponentProps<typeof VueFinalModal> {
31+
function byPassAllModalEvents(emit?: ComponentEmit<typeof VueFinalModal>): ComponentProps<typeof VueFinalModal> {
1432
return {
1533
'onUpdate:modelValue': (val: boolean) => emit?.('update:modelValue', val),
1634

@@ -23,21 +41,3 @@ export function byPassAllModalEvents(emit?: ComponentEmit<typeof VueFinalModal>)
2341
'onClickOutside': () => emit?.('clickOutside'),
2442
}
2543
}
26-
27-
export function useVfmAttrs<TP extends Component, MP extends Component>(options: {
28-
props: ComponentProps<TP>
29-
modalProps: ComponentProps<MP>
30-
emit?: any
31-
}) {
32-
const { props, modalProps, emit } = options
33-
const bindProps = computed(() => pickModalProps(props, modalProps))
34-
const bindEmits = byPassAllModalEvents(emit)
35-
const attrs = useAttrs()
36-
const vfmAttrs = computed(() => ({
37-
...bindProps.value,
38-
...bindEmits,
39-
...attrs,
40-
}))
41-
42-
return vfmAttrs
43-
}

0 commit comments

Comments
 (0)