Skip to content

Commit 96f5081

Browse files
committed
style: refactor vnode.js to ts
1 parent 414e7a1 commit 96f5081

File tree

5 files changed

+19
-34
lines changed

5 files changed

+19
-34
lines changed

components/_util/vnode.js renamed to components/_util/vnode.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import { filterEmpty } from './props-util';
2+
import type { VNode, VNodeProps } from 'vue';
23
import { cloneVNode } from 'vue';
34
import warning from './warning';
5+
import type { RefObject } from './createRef';
46

5-
export function cloneElement(vnode, nodeProps = {}, override = true, mergeRef = false) {
7+
export function cloneElement<T, U>(
8+
vnode: VNode<T, U> | VNode<T, U>[],
9+
nodeProps: Record<string, any> &
10+
Omit<VNodeProps, 'ref'> & { ref?: VNodeProps['ref'] | RefObject } = {},
11+
override = true,
12+
mergeRef = false,
13+
): VNode<T, U> {
614
let ele = vnode;
715
if (Array.isArray(vnode)) {
816
ele = filterEmpty(vnode)[0];
917
}
1018
if (!ele) {
1119
return null;
1220
}
13-
const node = cloneVNode(ele, nodeProps, mergeRef);
21+
const node = cloneVNode(ele as VNode<T, U>, nodeProps as any, mergeRef);
1422

1523
// cloneVNode内部是合并属性,这里改成覆盖属性
16-
node.props = override ? { ...node.props, ...nodeProps } : node.props;
24+
node.props = (override ? { ...node.props, ...nodeProps } : node.props) as any;
1725
warning(typeof node.props.class !== 'object', 'class must be string');
1826
return node;
1927
}

components/menu/src/Menu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Key } from '../../_util/type';
2-
import type { ExtractPropTypes, PropType } from 'vue';
2+
import type { ExtractPropTypes, PropType, VNode } from 'vue';
33
import { computed, defineComponent, ref, inject, watchEffect, watch, onMounted, unref } from 'vue';
44
import shallowEqual from '../../_util/shallowequal';
55
import type { StoreMenuInfo } from './hooks/useMenuContext';
@@ -357,7 +357,7 @@ export default defineComponent({
357357
let icon = props.expandIcon || slots.expandIcon;
358358
icon = typeof icon === 'function' ? icon(opt) : icon;
359359
return cloneElement(
360-
icon,
360+
icon as unknown as VNode,
361361
{
362362
class: `${prefixCls.value}-submenu-expand-icon`,
363363
},

components/vc-cascader/hooks/useDisplayValues.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
InternalFieldNames,
77
} from '../Cascader';
88
import { toPathKey } from '../utils/commonUtil';
9-
import type { Ref } from 'vue';
9+
import type { Ref, VNode } from 'vue';
1010
import { computed } from 'vue';
1111
import { isValidElement } from '../../_util/props-util';
1212
import { cloneElement } from '../../_util/vnode';
@@ -32,7 +32,9 @@ export default (
3232

3333
// If exist non-string value, use VueNode instead
3434
return mergedLabels.reduce((list, label, index) => {
35-
const keyedLabel = isValidElement(label) ? cloneElement(label, { key: index }) : label;
35+
const keyedLabel = isValidElement(label)
36+
? cloneElement(label as unknown as VNode, { key: index })
37+
: label;
3638

3739
if (index === 0) {
3840
return [keyedLabel];

components/vc-picker/panels/TimePanel/TimeBody.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { SharedTimeProps } from '.';
77
import { setTime as utilSetTime } from '../../utils/timeUtil';
88
import { cloneElement } from '../../../_util/vnode';
99
import type { VueNode } from '../../../_util/type';
10-
import type { Ref } from 'vue';
10+
import type { Ref, VNode } from 'vue';
1111
import { onBeforeUpdate, ref, watchEffect, computed, defineComponent } from 'vue';
1212

1313
function generateUnits(
@@ -245,7 +245,7 @@ const TimeBody = defineComponent({
245245
) {
246246
if (condition !== false) {
247247
columns.push({
248-
node: cloneElement(node, {
248+
node: cloneElement(node as unknown as VNode, {
249249
prefixCls: columnPrefixCls,
250250
value: columnValue,
251251
active: activeColumnIndex === columns.length,

components/vc-select/Selector/Input.tsx

-25
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,4 @@ const Input = defineComponent({
175175
},
176176
});
177177

178-
// Input.props = {
179-
// inputRef: PropTypes.any,
180-
// prefixCls: PropTypes.string,
181-
// id: PropTypes.string,
182-
// inputElement: PropTypes.any,
183-
// disabled: PropTypes.looseBool,
184-
// autofocus: PropTypes.looseBool,
185-
// autocomplete: PropTypes.string,
186-
// editable: PropTypes.looseBool,
187-
// accessibilityIndex: PropTypes.number,
188-
// value: PropTypes.string,
189-
// open: PropTypes.looseBool,
190-
// tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
191-
// /** Pass accessibility props to input */
192-
// attrs: PropTypes.object,
193-
// onKeydown: PropTypes.func,
194-
// onMousedown: PropTypes.func,
195-
// onChange: PropTypes.func,
196-
// onPaste: PropTypes.func,
197-
// onCompositionstart: PropTypes.func,
198-
// onCompositionend: PropTypes.func,
199-
// onFocus: PropTypes.func,
200-
// onBlur: PropTypes.func,
201-
// };
202-
203178
export default Input;

0 commit comments

Comments
 (0)