Skip to content

Commit 4465b73

Browse files
committed
Merge branch 'v2.3' into refactor-tree
2 parents 9785531 + 6f8a139 commit 4465b73

File tree

730 files changed

+21650
-16437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

730 files changed

+21650
-16437
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ site/dev.js
7373

7474
# IDE 语法提示临时文件
7575
vetur/
76+
77+
report.html

antd-tools/getWebpackConfig.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ function getWebpackConfig(modules) {
8080
},
8181

8282
module: {
83-
noParse: [/moment.js/],
8483
rules: [
8584
{
8685
test: /\.vue$/,

components/_util/EventInterface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type FocusEventHandler = (e: FocusEvent) => void;
2+
export type MouseEventHandler = (e: MouseEvent) => void;
3+
export type KeyboardEventHandler = (e: KeyboardEvent) => void;
4+
export type ChangeEvent = Event & {
5+
target: {
6+
value?: string | undefined;
7+
};
8+
};

components/_util/Portal.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
11
import PropTypes from './vue-types';
2-
import { defineComponent, nextTick, Teleport } from 'vue';
2+
import {
3+
defineComponent,
4+
nextTick,
5+
onBeforeUnmount,
6+
onMounted,
7+
onUpdated,
8+
ref,
9+
Teleport,
10+
} from 'vue';
311

412
export default defineComponent({
513
name: 'Portal',
14+
inheritAttrs: false,
615
props: {
716
getContainer: PropTypes.func.isRequired,
8-
children: PropTypes.any.isRequired,
917
didUpdate: PropTypes.func,
1018
},
11-
data() {
12-
this._container = null;
13-
return {};
14-
},
15-
mounted() {
16-
this.createContainer();
17-
},
18-
updated() {
19-
const { didUpdate } = this.$props;
20-
if (didUpdate) {
19+
setup(props, { slots }) {
20+
const container = ref();
21+
onMounted(() => {
22+
container.value = props.getContainer();
23+
});
24+
onUpdated(() => {
2125
nextTick(() => {
22-
didUpdate(this.$props);
26+
props.nextTick?.(props);
2327
});
24-
}
25-
},
26-
27-
beforeUnmount() {
28-
this.removeContainer();
29-
},
30-
methods: {
31-
createContainer() {
32-
this._container = this.$props.getContainer();
33-
this.$forceUpdate();
34-
},
35-
removeContainer() {
36-
if (this._container && this._container.parentNode) {
37-
this._container.parentNode.removeChild(this._container);
28+
});
29+
onBeforeUnmount(() => {
30+
if (container.value && container.value.parentNode) {
31+
container.value.parentNode.removeChild(container.value);
3832
}
39-
},
40-
},
41-
42-
render() {
43-
if (this._container) {
44-
return <Teleport to={this._container}>{this.$props.children}</Teleport>;
45-
}
46-
return null;
33+
});
34+
return () => {
35+
return container.value ? <Teleport to={container.value}>{slots.default?.()}</Teleport> : null;
36+
};
4737
},
4838
});

components/_util/PortalWrapper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default defineComponent({
2020
wrapperClassName: PropTypes.string,
2121
forceRender: PropTypes.looseBool,
2222
getContainer: PropTypes.any,
23-
children: PropTypes.func,
2423
visible: PropTypes.looseBool,
2524
},
2625
data() {
@@ -130,7 +129,7 @@ export default defineComponent({
130129
},
131130

132131
render() {
133-
const { children, forceRender, visible } = this.$props;
132+
const { forceRender, visible } = this.$props;
134133
let portal = null;
135134
const childProps = {
136135
getOpenCount: () => openCount,
@@ -141,8 +140,8 @@ export default defineComponent({
141140
portal = (
142141
<Portal
143142
getContainer={this.getDomContainer}
144-
children={children(childProps)}
145143
ref={this.savePortal}
144+
v-slots={{ default: () => this.$slots.default?.(childProps) }}
146145
></Portal>
147146
);
148147
}

components/_util/hooks/useConfigInject.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default (
1010
): {
1111
configProvider: UnwrapRef<ConfigProviderProps>;
1212
prefixCls: ComputedRef<string>;
13+
rootPrefixCls: ComputedRef<string>;
1314
direction: ComputedRef<Direction>;
1415
size: ComputedRef<SizeType>;
1516
getTargetContainer: ComputedRef<() => HTMLElement>;
@@ -30,12 +31,12 @@ export default (
3031
);
3132
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
3233
const direction = computed(() => props.direction ?? configProvider.direction);
34+
const rootPrefixCls = computed(() => configProvider.getPrefixCls());
3335
const autoInsertSpaceInButton = computed(() => configProvider.autoInsertSpaceInButton);
3436
const renderEmpty = computed(() => configProvider.renderEmpty);
3537
const space = computed(() => configProvider.space);
3638
const pageHeader = computed(() => configProvider.pageHeader);
3739
const form = computed(() => configProvider.form);
38-
const size = computed(() => props.size ?? configProvider.componentSize);
3940
const getTargetContainer = computed(
4041
() => props.getTargetContainer || configProvider.getTargetContainer,
4142
);
@@ -46,19 +47,21 @@ export default (
4647
const dropdownMatchSelectWidth = computed<boolean>(
4748
() => props.dropdownMatchSelectWidth ?? configProvider.dropdownMatchSelectWidth,
4849
);
50+
const size = computed(() => props.size || configProvider.componentSize);
4951
return {
5052
configProvider,
5153
prefixCls,
5254
direction,
5355
size,
5456
getTargetContainer,
57+
getPopupContainer,
5558
space,
5659
pageHeader,
5760
form,
5861
autoInsertSpaceInButton,
5962
renderEmpty,
6063
virtual,
6164
dropdownMatchSelectWidth,
62-
getPopupContainer,
65+
rootPrefixCls,
6366
};
6467
};

components/_util/hooks/useMemo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Ref } from 'vue';
1+
import type { Ref, WatchSource } from 'vue';
22
import { ref, watch } from 'vue';
33

44
export default function useMemo<T>(
55
getValue: () => T,
6-
condition: any[],
6+
condition: (WatchSource<unknown> | object)[],
77
shouldUpdate?: (prev: any[], next: any[]) => boolean,
88
) {
99
const cacheRef: Ref<T> = ref(getValue() as any);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { Ref, UnwrapRef } from 'vue';
2+
import { toRaw } from 'vue';
3+
import { watchEffect } from 'vue';
4+
import { unref } from 'vue';
5+
import { watch } from 'vue';
6+
import { ref } from 'vue';
7+
8+
export default function useMergedState<T, R = Ref<T>>(
9+
defaultStateValue: T | (() => T),
10+
option?: {
11+
defaultValue?: T | (() => T);
12+
value?: Ref<T> | Ref<UnwrapRef<T>>;
13+
onChange?: (val: T, prevValue: T) => void;
14+
postState?: (val: T) => T;
15+
},
16+
): [R, (val: T) => void] {
17+
const { defaultValue, value = ref() } = option || {};
18+
let initValue: T =
19+
typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue;
20+
if (value.value !== undefined) {
21+
initValue = unref(value as any) as T;
22+
}
23+
if (defaultValue !== undefined) {
24+
initValue = typeof defaultValue === 'function' ? (defaultValue as any)() : defaultValue;
25+
}
26+
27+
const innerValue = ref(initValue) as Ref<T>;
28+
const mergedValue = ref(initValue) as Ref<T>;
29+
watchEffect(() => {
30+
let val = value.value !== undefined ? value.value : innerValue.value;
31+
if (option.postState) {
32+
val = option.postState(val as T);
33+
}
34+
mergedValue.value = val as T;
35+
});
36+
37+
function triggerChange(newValue: T) {
38+
const preVal = mergedValue.value;
39+
innerValue.value = newValue;
40+
if (toRaw(mergedValue.value) !== newValue && option.onChange) {
41+
option.onChange(newValue, preVal);
42+
}
43+
}
44+
45+
// Effect of reset value to `undefined`
46+
watch(value, () => {
47+
innerValue.value = value.value as T;
48+
});
49+
50+
return [mergedValue as unknown as R, triggerChange];
51+
}

components/_util/hooks/useRef.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { Ref } from 'vue';
22
import { onBeforeUpdate, ref } from 'vue';
33

44
export type UseRef = [(el: any, key: string | number) => void, Ref<any>];
5-
5+
export type Refs = Record<string | number, any>;
66
export const useRef = (): UseRef => {
7-
const refs = ref<any>({});
7+
const refs = ref<Refs>({});
88
const setRef = (el: any, key: string | number) => {
99
refs.value[key] = el;
1010
};
@@ -13,3 +13,5 @@ export const useRef = (): UseRef => {
1313
});
1414
return [setRef, refs];
1515
};
16+
17+
export default useRef;

components/_util/hooks/useState.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Ref } from 'vue';
2+
import { ref } from 'vue';
3+
4+
export default function useState<T, R = Ref<T>>(
5+
defaultStateValue: T | (() => T),
6+
): [R, (val: T) => void] {
7+
const initValue: T =
8+
typeof defaultStateValue === 'function' ? (defaultStateValue as any)() : defaultStateValue;
9+
10+
const innerValue = ref(initValue) as Ref<T>;
11+
12+
function triggerChange(newValue: T) {
13+
innerValue.value = newValue;
14+
}
15+
16+
return [innerValue as unknown as R, triggerChange];
17+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy