From d6cc262c3a9eb1e2f380ce6db8d390e2b014aa38 Mon Sep 17 00:00:00 2001 From: extclp <2842417407@qq.com> Date: Thu, 25 Apr 2024 09:25:29 +0800 Subject: [PATCH] refactor: replement deprecated fields (#7519) --- antd-tools/generator-types/src/index.ts | 6 +++--- antd-tools/generator-types/src/parser.ts | 8 ++++---- antd-tools/getTSCommonConfig.js | 3 +-- components/_util/getScroll.ts | 2 +- components/_util/scrollTo.ts | 4 ++-- components/_util/triggerEvent.ts | 8 -------- components/checkbox/Group.tsx | 2 +- components/menu/src/Menu.tsx | 2 +- components/menu/src/hooks/useItems.tsx | 2 +- components/rate/util.ts | 2 +- components/tree/demo/search.vue | 4 ++-- components/vc-image/src/PreviewGroup.tsx | 2 +- components/vc-picker/panels/TimePanel/TimeUnitColumn.tsx | 2 +- components/vc-slider/src/common/createSlider.tsx | 2 +- components/vc-slider/src/utils.ts | 2 +- components/vc-tree-select/hooks/useDataEntities.ts | 2 +- components/vc-tree/utils/treeUtil.ts | 2 +- components/vc-util/Dom/css.ts | 5 ++--- components/vc-util/isMobile.ts | 2 +- package.json | 5 ----- .../vue-colorful/components/common/Interactive.tsx | 4 ++-- site/src/components/vue-colorful/hooks/useStyleSheet.ts | 2 +- site/src/layouts/header/Menu.vue | 2 +- 23 files changed, 30 insertions(+), 45 deletions(-) delete mode 100644 components/_util/triggerEvent.ts diff --git a/antd-tools/generator-types/src/index.ts b/antd-tools/generator-types/src/index.ts index 12d2bc98b..aad960d39 100644 --- a/antd-tools/generator-types/src/index.ts +++ b/antd-tools/generator-types/src/index.ts @@ -21,13 +21,13 @@ async function readMarkdown(options: Options): Promise> { return formatter(mdParser(fileContent), componentName, kebabComponentName, options.tagPrefix); }) .filter(item => item) as VueTag[][]; - const tags: Map = new Map(); + const tags = new Map(); flatMap(data, item => item).forEach(mergedTag => mergeTag(tags, mergedTag)); return tags; } function readTypings(options: Options): Map { - const tags: Map = new Map(); + const tags = new Map(); const fileContent = readFileSync(options.typingsPath, 'utf-8'); fileContent .split('\n') @@ -61,7 +61,7 @@ function mergeTag(tags: Map, mergedTag: VueTag) { function mergeTags(mergedTagsArr: Map[]): VueTag[] { if (mergedTagsArr.length === 1) return [...mergedTagsArr[0].values()]; - const tags: Map = new Map(); + const tags = new Map(); if (mergedTagsArr.length === 0) return []; mergedTagsArr.forEach(mergedTags => { mergedTags.forEach(mergedTag => mergeTag(tags, mergedTag)); diff --git a/antd-tools/generator-types/src/parser.ts b/antd-tools/generator-types/src/parser.ts index 59f7d2483..bdcafb3d5 100644 --- a/antd-tools/generator-types/src/parser.ts +++ b/antd-tools/generator-types/src/parser.ts @@ -21,7 +21,7 @@ export type Articals = Artical[]; function readLine(input: string) { const end = input.indexOf('\n'); - return input.substr(0, end !== -1 ? end : input.length); + return input.substring(0, end !== -1 ? end : input.length); } function splitTableLine(line: string) { @@ -47,7 +47,7 @@ function tableParse(input: string) { }; while (start < end) { - const target = input.substr(start); + const target = input.substring(start); const line = readLine(target); if (!/^\|/.test(target)) { @@ -79,7 +79,7 @@ export function mdParser(input: string): Articals { const end = input.length; while (start < end) { - const target = input.substr(start); + const target = input.substring(start); let match; if ((match = TITLE_REG.exec(target))) { @@ -91,7 +91,7 @@ export function mdParser(input: string): Articals { start += match.index + match[0].length; } else if ((match = TABLE_REG.exec(target))) { - const { table, usedLength } = tableParse(target.substr(match.index)); + const { table, usedLength } = tableParse(target.substring(match.index)); artical.push({ type: 'table', table, diff --git a/antd-tools/getTSCommonConfig.js b/antd-tools/getTSCommonConfig.js index d935888c4..fd2a33ff6 100644 --- a/antd-tools/getTSCommonConfig.js +++ b/antd-tools/getTSCommonConfig.js @@ -1,7 +1,6 @@ 'use strict'; const fs = require('fs'); -const assign = require('object-assign'); const { getProjectPath } = require('./utils/projectHelper'); module.exports = function () { @@ -9,7 +8,7 @@ module.exports = function () { if (fs.existsSync(getProjectPath('tsconfig.json'))) { my = require(getProjectPath('tsconfig.json')); } - return assign( + return Object.assign( { noUnusedParameters: true, noUnusedLocals: true, diff --git a/components/_util/getScroll.ts b/components/_util/getScroll.ts index 2889b43ed..ca0b10005 100644 --- a/components/_util/getScroll.ts +++ b/components/_util/getScroll.ts @@ -12,7 +12,7 @@ export default function getScroll( const method = top ? 'scrollTop' : 'scrollLeft'; let result = 0; if (isWindow(target)) { - result = target[top ? 'pageYOffset' : 'pageXOffset']; + result = target[top ? 'scrollY' : 'scrollX']; } else if (target instanceof Document) { result = target.documentElement[method]; } else if (target instanceof HTMLElement) { diff --git a/components/_util/scrollTo.ts b/components/_util/scrollTo.ts index c9dbb8910..992d6a930 100644 --- a/components/_util/scrollTo.ts +++ b/components/_util/scrollTo.ts @@ -22,8 +22,8 @@ export default function scrollTo(y: number, options: ScrollToOptions = {}) { const time = timestamp - startTime; const nextScrollTop = easeInOutCubic(time > duration ? duration : time, scrollTop, y, duration); if (isWindow(container)) { - (container as Window).scrollTo(window.pageXOffset, nextScrollTop); - } else if (container instanceof Document || container.constructor.name === 'HTMLDocument') { + (container as Window).scrollTo(window.scrollX, nextScrollTop); + } else if (container instanceof Document) { (container as Document).documentElement.scrollTop = nextScrollTop; } else { (container as HTMLElement).scrollTop = nextScrollTop; diff --git a/components/_util/triggerEvent.ts b/components/_util/triggerEvent.ts deleted file mode 100644 index 3c8cfc541..000000000 --- a/components/_util/triggerEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default function triggerEvent(el: Element, type: string) { - if ('createEvent' in document) { - // modern browsers, IE9+ - const e = document.createEvent('HTMLEvents'); - e.initEvent(type, false, true); - el.dispatchEvent(e); - } -} diff --git a/components/checkbox/Group.tsx b/components/checkbox/Group.tsx index 57fb871ba..f62380f73 100644 --- a/components/checkbox/Group.tsx +++ b/components/checkbox/Group.tsx @@ -41,7 +41,7 @@ export default defineComponent({ }); }); const triggerUpdate = ref(Symbol()); - const registeredValuesMap = ref>(new Map()); + const registeredValuesMap = ref(new Map()); const cancelValue = (id: Symbol) => { registeredValuesMap.value.delete(id); triggerUpdate.value = Symbol(); diff --git a/components/menu/src/Menu.tsx b/components/menu/src/Menu.tsx index 9c5956a0c..bd8addbfa 100644 --- a/components/menu/src/Menu.tsx +++ b/components/menu/src/Menu.tsx @@ -112,7 +112,7 @@ export default defineComponent({ return !override; }), ); - const store = shallowRef>(new Map()); + const store = shallowRef(new Map()); const siderCollapsed = inject(SiderCollapsedKey, ref(undefined)); const inlineCollapsed = computed(() => { if (siderCollapsed.value !== undefined) { diff --git a/components/menu/src/hooks/useItems.tsx b/components/menu/src/hooks/useItems.tsx index 322493b66..e1164f3af 100644 --- a/components/menu/src/hooks/useItems.tsx +++ b/components/menu/src/hooks/useItems.tsx @@ -116,7 +116,7 @@ function convertItemsToNodes( export default function useItems(props: MenuProps) { const itemsNodes = shallowRef([]); const hasItmes = shallowRef(false); - const store = shallowRef>(new Map()); + const store = shallowRef(new Map()); watch( () => props.items, () => { diff --git a/components/rate/util.ts b/components/rate/util.ts index 1bc62e2a4..a1a8c0ada 100644 --- a/components/rate/util.ts +++ b/components/rate/util.ts @@ -1,5 +1,5 @@ function getScroll(w: Window) { - let ret = w.pageXOffset; + let ret = w.scrollX; const method = 'scrollLeft'; if (typeof ret !== 'number') { const d = w.document; diff --git a/components/tree/demo/search.vue b/components/tree/demo/search.vue index 973851290..3f94f16f3 100644 --- a/components/tree/demo/search.vue +++ b/components/tree/demo/search.vue @@ -27,9 +27,9 @@ Searchable Tree. > diff --git a/components/vc-image/src/PreviewGroup.tsx b/components/vc-image/src/PreviewGroup.tsx index 55d81d5ae..fe432dc21 100644 --- a/components/vc-image/src/PreviewGroup.tsx +++ b/components/vc-image/src/PreviewGroup.tsx @@ -95,7 +95,7 @@ const Group = defineComponent({ ? mergeDefaultValue(props.preview, defaultValues) : defaultValues; }); - const previewUrls = reactive>(new Map()); + const previewUrls = reactive(new Map()); const current = ref(); const previewVisible = computed(() => preview.value.visible); diff --git a/components/vc-picker/panels/TimePanel/TimeUnitColumn.tsx b/components/vc-picker/panels/TimePanel/TimeUnitColumn.tsx index de70c157e..15e3544a9 100644 --- a/components/vc-picker/panels/TimePanel/TimeUnitColumn.tsx +++ b/components/vc-picker/panels/TimePanel/TimeUnitColumn.tsx @@ -25,7 +25,7 @@ export default defineComponent({ const { open } = useInjectPanel(); const ulRef = shallowRef(null); - const liRefs = ref>(new Map()); + const liRefs = ref(new Map()); const scrollRef = ref(); watch( diff --git a/components/vc-slider/src/common/createSlider.tsx b/components/vc-slider/src/common/createSlider.tsx index 4713b50ca..cdb37dc99 100644 --- a/components/vc-slider/src/common/createSlider.tsx +++ b/components/vc-slider/src/common/createSlider.tsx @@ -210,7 +210,7 @@ export default function createSlider(Component) { if (vertical) { return reverse ? rect.bottom : rect.top; } - return window.pageXOffset + (reverse ? rect.right : rect.left); + return window.scrollX + (reverse ? rect.right : rect.left); }, getSliderLength() { const slider = this.sliderRef; diff --git a/components/vc-slider/src/utils.ts b/components/vc-slider/src/utils.ts index 124033575..0a0413e11 100644 --- a/components/vc-slider/src/utils.ts +++ b/components/vc-slider/src/utils.ts @@ -58,7 +58,7 @@ export function getHandleCenterPosition(vertical: boolean, handle: HTMLElement) const coords = handle.getBoundingClientRect(); return vertical ? coords.top + coords.height * 0.5 - : window.pageXOffset + coords.left + coords.width * 0.5; + : window.scrollX + coords.left + coords.width * 0.5; } export function ensureValueInRange(val: number, { max, min }: { max?: number; min?: number }) { diff --git a/components/vc-tree-select/hooks/useDataEntities.ts b/components/vc-tree-select/hooks/useDataEntities.ts index f534482ad..14efd8f5e 100644 --- a/components/vc-tree-select/hooks/useDataEntities.ts +++ b/components/vc-tree-select/hooks/useDataEntities.ts @@ -8,7 +8,7 @@ import { shallowRef, watchEffect } from 'vue'; import { warning } from '../../vc-util/warning'; export default (treeData: ShallowRef, fieldNames: Ref) => { - const valueEntities = shallowRef>(new Map()); + const valueEntities = shallowRef(new Map()); const keyEntities = shallowRef>({}); watchEffect(() => { const fieldNamesValue = fieldNames.value; diff --git a/components/vc-tree/utils/treeUtil.ts b/components/vc-tree/utils/treeUtil.ts index 77a373ef8..b9679924a 100644 --- a/components/vc-tree/utils/treeUtil.ts +++ b/components/vc-tree/utils/treeUtil.ts @@ -40,7 +40,7 @@ export function fillFieldNames(fieldNames?: FieldNames): Required { * Warning if TreeNode do not provides key */ export function warningWithoutKey(treeData: DataNode[], fieldNames: FieldNames) { - const keys: Map = new Map(); + const keys = new Map(); function dig(list: DataNode[], path = '') { (list || []).forEach(treeNode => { diff --git a/components/vc-util/Dom/css.ts b/components/vc-util/Dom/css.ts index 99de2383b..dc5efa4f1 100644 --- a/components/vc-util/Dom/css.ts +++ b/components/vc-util/Dom/css.ts @@ -101,15 +101,14 @@ export function getOffset(node: any) { const box = node.getBoundingClientRect(); const docElem = document.documentElement; - // < ie8 不支持 win.pageXOffset, 则使用 docElem.scrollLeft return { left: box.left + - (window.pageXOffset || docElem.scrollLeft) - + (window.scrollX || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0), top: box.top + - (window.pageYOffset || docElem.scrollTop) - + (window.scrollY || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0), }; } diff --git a/components/vc-util/isMobile.ts b/components/vc-util/isMobile.ts index 7bfc04ccd..a7b6a5f0c 100644 --- a/components/vc-util/isMobile.ts +++ b/components/vc-util/isMobile.ts @@ -9,7 +9,7 @@ export default () => { agent, ) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test( - agent?.substr(0, 4), + agent?.substring(0, 4), ) ); }; diff --git a/package.json b/package.json index b270943f6..08d9a73e9 100644 --- a/package.json +++ b/package.json @@ -216,7 +216,6 @@ "mockdate": "^2.0.2", "moment": "^2.29.1", "nprogress": "^0.2.0", - "object-assign": "^4.1.1", "postcss": "^8.2.12", "postcss-loader": "^6.0.0", "prettier": "^2.2.0", @@ -308,10 +307,6 @@ "dist/*", "*.css" ], - "vetur": { - "tags": "vetur/tags.json", - "attributes": "vetur/attributes.json" - }, "config": { "commitizen": { "path": "node_modules/cz-git", diff --git a/site/src/components/vue-colorful/components/common/Interactive.tsx b/site/src/components/vue-colorful/components/common/Interactive.tsx index e42299dd1..3c65b43f7 100644 --- a/site/src/components/vue-colorful/components/common/Interactive.tsx +++ b/site/src/components/vue-colorful/components/common/Interactive.tsx @@ -36,8 +36,8 @@ const getRelativePosition = ( const pointer = isTouch(event) ? getTouchPoint(event.touches, touchId) : (event as MouseEvent); return { - left: clamp((pointer.pageX - (rect.left + getParentWindow(node).pageXOffset)) / rect.width), - top: clamp((pointer.pageY - (rect.top + getParentWindow(node).pageYOffset)) / rect.height), + left: clamp((pointer.pageX - (rect.left + getParentWindow(node).scrollX)) / rect.width), + top: clamp((pointer.pageY - (rect.top + getParentWindow(node).scrollY)) / rect.height), }; }; diff --git a/site/src/components/vue-colorful/hooks/useStyleSheet.ts b/site/src/components/vue-colorful/hooks/useStyleSheet.ts index c635fdbf1..d158599bc 100644 --- a/site/src/components/vue-colorful/hooks/useStyleSheet.ts +++ b/site/src/components/vue-colorful/hooks/useStyleSheet.ts @@ -6,7 +6,7 @@ import { getNonce } from '../utils/nonce'; // Bundler is configured to load this as a processed minified CSS-string import styles from '../css/styles.css'; -const styleElementMap: Map = new Map(); +const styleElementMap = new Map(); /** * Injects CSS code into the document's diff --git a/site/src/layouts/header/Menu.vue b/site/src/layouts/header/Menu.vue index 5cdff38ee..1c9e4937d 100644 --- a/site/src/layouts/header/Menu.vue +++ b/site/src/layouts/header/Menu.vue @@ -56,7 +56,7 @@ export default defineComponent({ location: { pathname }, } = window; const currentProtocol = `${window.location.protocol}//`; - const currentHref = window.location.href.substr(currentProtocol.length); + const currentHref = window.location.href.substring(currentProtocol.length); if (isLocalStorageNameSupported()) { localStorage.setItem('locale', isZhCN(pathname) ? 'en-US' : 'zh-CN');