From 389f6b3202ec3c6feacbf257ee3ff0f9f4833131 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 26 Nov 2024 16:23:23 +0800 Subject: [PATCH] refactor: remove lodash Signed-off-by: Innei --- package.json | 4 ++-- pnpm-lock.yaml | 22 +++++++++++++----- src/components/config-form/index.tsx | 2 +- .../components/image-detail-section.tsx | 2 +- src/components/drawer/text-base-drawer.tsx | 12 ++++++---- src/components/kv-editor/index.tsx | 2 +- src/components/location/search-button.tsx | 10 ++++---- src/components/special-button/preview.tsx | 2 +- src/hooks/use-storage.ts | 2 +- src/stores/ui.ts | 2 +- src/utils/index.ts | 3 ++- src/utils/rest.ts | 2 +- src/views/analyze/index.tsx | 13 ++++++----- src/views/dashboard/index.tsx | 2 +- src/views/extra-features/markdown-helper.tsx | 2 +- .../extra-features/snippets/tabs/for-edit.tsx | 16 ++++++------- src/views/extra-features/webhook/index.tsx | 2 +- src/views/maintenance/pty/index.tsx | 23 ++++++++++--------- src/views/manage-notes/write.tsx | 2 +- src/views/manage-pages/write.tsx | 2 +- src/views/manage-posts/write.tsx | 2 +- src/views/manage-project/edit.tsx | 16 +++++++------ src/views/manage-says/edit.tsx | 18 ++++++++------- src/views/setting/tabs/system.tsx | 2 +- src/views/setting/tabs/user.tsx | 22 ++++++++++-------- 25 files changed, 105 insertions(+), 82 deletions(-) diff --git a/package.json b/package.json index 0c63b92dd..71ddee96a 100644 --- a/package.json +++ b/package.json @@ -65,12 +65,13 @@ "crossbell.js": "npm:crossbell@1.12.1", "date-fns": "3.6.0", "ejs": "3.1.10", + "es-toolkit": "1.27.0", "event-source-polyfill": "1.0.31", "highlight.js": "11.10.0", "js-cookie": "3.0.5", "js-yaml": "4.1.0", "json5": "2.2.3", - "lodash-es": "4.17.21", + "lodash.transform": "4.6.0", "markdown-escape": "2.0.0", "marked": "13.0.3", "monaco-editor": "0.50.0", @@ -103,7 +104,6 @@ "@types/ejs": "3.1.5", "@types/event-source-polyfill": "1.0.5", "@types/js-yaml": "4.0.9", - "@types/lodash-es": "4.17.12", "@types/markdown-escape": "1.1.3", "@types/qs": "6.9.17", "@types/sortablejs": "1.15.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af9847ad5..235c5c8cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -119,6 +119,9 @@ importers: ejs: specifier: 3.1.10 version: 3.1.10 + es-toolkit: + specifier: 1.27.0 + version: 1.27.0 event-source-polyfill: specifier: 1.0.31 version: 1.0.31 @@ -134,9 +137,9 @@ importers: json5: specifier: 2.2.3 version: 2.2.3 - lodash-es: - specifier: 4.17.21 - version: 4.17.21 + lodash.transform: + specifier: 4.6.0 + version: 4.6.0 markdown-escape: specifier: 2.0.0 version: 2.0.0 @@ -228,9 +231,6 @@ importers: '@types/js-yaml': specifier: 4.0.9 version: 4.0.9 - '@types/lodash-es': - specifier: 4.17.12 - version: 4.17.12 '@types/markdown-escape': specifier: 1.1.3 version: 1.1.3 @@ -2482,6 +2482,9 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + es-toolkit@1.27.0: + resolution: {integrity: sha512-ETSFA+ZJArcuSCpzD2TjAy6UHpx4E4uqFsoDg9F/nTLogrLmVVZQ+zNxco5h7cWnA1nNak07IXsLcaSMih+ZPQ==} + esbuild@0.21.5: resolution: {integrity: sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==} engines: {node: '>=12'} @@ -2856,6 +2859,9 @@ packages: lodash-es@4.17.21: resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} + lodash.transform@4.6.0: + resolution: {integrity: sha512-LO37ZnhmBVx0GvOU/caQuipEh4GN82TcWv3yHlebGDgOxbxiwwzW5Pcx2AcvpIv2WmvmSMoC492yQFNhy/l/UQ==} + lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} @@ -6532,6 +6538,8 @@ snapshots: es-errors@1.3.0: {} + es-toolkit@1.27.0: {} + esbuild@0.21.5: optionalDependencies: '@esbuild/aix-ppc64': 0.21.5 @@ -6881,6 +6889,8 @@ snapshots: lodash-es@4.17.21: {} + lodash.transform@4.6.0: {} + lodash@4.17.21: {} log-update@6.1.0: diff --git a/src/components/config-form/index.tsx b/src/components/config-form/index.tsx index 77b9d5247..e06eccc28 100644 --- a/src/components/config-form/index.tsx +++ b/src/components/config-form/index.tsx @@ -1,4 +1,4 @@ -import { get, set } from 'lodash-es' +import { get, set } from 'es-toolkit/compat' import { marked } from 'marked' import { NCollapse, diff --git a/src/components/drawer/components/image-detail-section.tsx b/src/components/drawer/components/image-detail-section.tsx index dc21f035e..9e18f174b 100644 --- a/src/components/drawer/components/image-detail-section.tsx +++ b/src/components/drawer/components/image-detail-section.tsx @@ -1,5 +1,5 @@ import { decode } from 'blurhash' -import { uniqBy } from 'lodash-es' +import { uniqBy } from 'es-toolkit/compat' import { NButton, NButtonGroup, diff --git a/src/components/drawer/text-base-drawer.tsx b/src/components/drawer/text-base-drawer.tsx index 9a495c9e2..fde5f595e 100644 --- a/src/components/drawer/text-base-drawer.tsx +++ b/src/components/drawer/text-base-drawer.tsx @@ -1,6 +1,5 @@ import { isURL } from 'class-validator' -import { JSONHighlight } from '~/components/json-highlight' -import { isObject, isUndefined } from 'lodash-es' +import { isObject, isUndefined } from 'es-toolkit/compat' import { NButton, NCollapse, @@ -20,13 +19,16 @@ import { NSwitch, NTooltip, } from 'naive-ui' -import { JSONParseReturnOriginal } from '~/utils/json' -import { ImageDetailSection } from './components/image-detail-section' -import { JSONEditor } from './components/json-editor' import type { Image } from '@mx-space/api-client' import type { SelectOption } from 'naive-ui' import type { PropType } from 'vue' +import { JSONHighlight } from '~/components/json-highlight' +import { JSONParseReturnOriginal } from '~/utils/json' + +import { ImageDetailSection } from './components/image-detail-section' +import { JSONEditor } from './components/json-editor' + type ItemType = 'date-picker' export const TextBaseDrawer = defineComponent({ props: { diff --git a/src/components/kv-editor/index.tsx b/src/components/kv-editor/index.tsx index ab3d4ef47..6dfc39f0c 100644 --- a/src/components/kv-editor/index.tsx +++ b/src/components/kv-editor/index.tsx @@ -1,4 +1,4 @@ -import { isEmpty } from 'lodash-es' +import { isEmpty } from 'es-toolkit/compat' import { NDynamicInput, NInput, NSelect } from 'naive-ui' import type { SelectMixedOption } from 'naive-ui/lib/select/src/interface' import type { PropType } from 'vue' diff --git a/src/components/location/search-button.tsx b/src/components/location/search-button.tsx index 261a7508a..dc654b67f 100644 --- a/src/components/location/search-button.tsx +++ b/src/components/location/search-button.tsx @@ -1,5 +1,4 @@ -import { SearchIcon } from '~/components/icons' -import { debounce } from 'lodash-es' +import { debounce } from 'es-toolkit/compat' import { NAutoComplete, NButton, @@ -9,13 +8,16 @@ import { NModal, NSpace, } from 'naive-ui' -import { RESTManager } from '~/utils/rest' import { defineComponent, ref, watch } from 'vue' -import { Icon } from '@vicons/utils' import type { AMapSearch } from '~/models/amap' import type { AutoCompleteOption } from 'naive-ui/lib/auto-complete/src/interface' import type { PropType } from 'vue' +import { Icon } from '@vicons/utils' + +import { SearchIcon } from '~/components/icons' +import { RESTManager } from '~/utils/rest' + export const SearchLocationButton = defineComponent({ props: { placeholder: { diff --git a/src/components/special-button/preview.tsx b/src/components/special-button/preview.tsx index 88363dd3f..52dfa6c1b 100644 --- a/src/components/special-button/preview.tsx +++ b/src/components/special-button/preview.tsx @@ -1,4 +1,4 @@ -import { debounce } from 'lodash-es' +import { debounce } from 'es-toolkit/compat' import { NSplit } from 'naive-ui' import { useUIStore } from '~/stores/ui' diff --git a/src/hooks/use-storage.ts b/src/hooks/use-storage.ts index 607f9a8fc..30c4eeb36 100644 --- a/src/hooks/use-storage.ts +++ b/src/hooks/use-storage.ts @@ -1,6 +1,6 @@ import { instanceToPlain, plainToInstance } from 'class-transformer' import { validateSync } from 'class-validator' -import { throttle } from 'lodash-es' +import { throttle } from 'es-toolkit/compat' import { reactive, watch } from 'vue' const key2reactive = new Map() diff --git a/src/stores/ui.ts b/src/stores/ui.ts index 5aabde12e..7454c69a0 100644 --- a/src/stores/ui.ts +++ b/src/stores/ui.ts @@ -6,7 +6,7 @@ * @FilePath: /admin-next/src/stores/ui.ts * Mark: Coding with Love */ -import { debounce } from 'lodash-es' +import { debounce } from 'es-toolkit/compat' import { computed, onMounted, ref, watch } from 'vue' import { useDark, useToggle } from '@vueuse/core' diff --git a/src/utils/index.ts b/src/utils/index.ts index 5f4fce19c..c2aff2539 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ -import { isEqual, isObject, transform } from 'lodash-es' +import { isEqual, isObject } from 'es-toolkit/compat' +import transform from 'lodash.transform' import { toRaw } from 'vue' export * from './auth' diff --git a/src/utils/rest.ts b/src/utils/rest.ts index f98bf2d4e..ee5e11c24 100644 --- a/src/utils/rest.ts +++ b/src/utils/rest.ts @@ -1,4 +1,4 @@ -import { isPlainObject } from 'lodash-es' +import { isPlainObject } from 'es-toolkit/compat' import { extend } from 'umi-request' import type { RequestMethod, RequestOptionsInit } from 'umi-request' diff --git a/src/views/analyze/index.tsx b/src/views/analyze/index.tsx index 623ba965c..805c001aa 100644 --- a/src/views/analyze/index.tsx +++ b/src/views/analyze/index.tsx @@ -1,6 +1,4 @@ -import { IpInfoPopover } from '~/components/ip-info' -import { ContentLayout } from '~/layouts/content' -import { isEmpty } from 'lodash-es' +import { isEmpty } from 'es-toolkit/compat' import { NButton, NDataTable, @@ -11,7 +9,6 @@ import { NTabs, useDialog, } from 'naive-ui' -import { RESTManager } from '~/utils' import { defineComponent, onBeforeMount, @@ -20,16 +17,20 @@ import { toRaw, watch, } from 'vue' +import type { IPAggregate, Month, Path, Today, Total, Week } from './types' import { Chart } from '@antv/g2/esm' +import { IpInfoPopover } from '~/components/ip-info' +import { ContentLayout } from '~/layouts/content' +import { RESTManager } from '~/utils' + import { AnalyzeDataTable } from './components/analyze-data-table' import { GuestActivity } from './components/guest-activity' import { ReadingRank } from './components/reading-rank' -import type { IPAggregate, Month, Path, Today, Total, Week } from './types' const SectionTitle = defineComponent((_, { slots }) => () => ( -
{slots.default?.()}
+
{slots.default?.()}
)) export default defineComponent({ setup() { diff --git a/src/views/dashboard/index.tsx b/src/views/dashboard/index.tsx index d1c4f04fc..f565c25b4 100644 --- a/src/views/dashboard/index.tsx +++ b/src/views/dashboard/index.tsx @@ -1,4 +1,4 @@ -import { pick } from 'lodash-es' +import { pick } from 'es-toolkit/compat' import { NButton, NCard, diff --git a/src/views/extra-features/markdown-helper.tsx b/src/views/extra-features/markdown-helper.tsx index 3b72f67c4..e89ead105 100644 --- a/src/views/extra-features/markdown-helper.tsx +++ b/src/views/extra-features/markdown-helper.tsx @@ -1,4 +1,4 @@ -import { debounce } from 'lodash-es' +import { debounce } from 'es-toolkit/compat' import { NButton, NButtonGroup, diff --git a/src/views/extra-features/snippets/tabs/for-edit.tsx b/src/views/extra-features/snippets/tabs/for-edit.tsx index cb43f3c0f..2f1ccb9d2 100644 --- a/src/views/extra-features/snippets/tabs/for-edit.tsx +++ b/src/views/extra-features/snippets/tabs/for-edit.tsx @@ -1,11 +1,6 @@ -import { HeaderActionButton } from '~/components/button/rounded-button' -import { CheckCircleOutlinedIcon } from '~/components/icons' -import { KVEditor } from '~/components/kv-editor' +import { omit } from 'es-toolkit/compat' import { dump, load } from 'js-yaml' import JSON5 from 'json5' -import { useLayout } from '~/layouts/content' -import { TwoColGridLayout } from '~/layouts/two-col' -import { omit } from 'lodash-es' import { NForm, NFormItem, @@ -17,18 +12,23 @@ import { NSwitch, useMessage, } from 'naive-ui' -import { RESTManager } from '~/utils' import { useRoute, useRouter } from 'vue-router' import { useStorage } from '@vueuse/core' +import { HeaderActionButton } from '~/components/button/rounded-button' +import { CheckCircleOutlinedIcon } from '~/components/icons' +import { KVEditor } from '~/components/kv-editor' import { useMountAndUnmount } from '~/hooks/use-lifecycle' +import { useLayout } from '~/layouts/content' +import { TwoColGridLayout } from '~/layouts/two-col' +import { RESTManager } from '~/utils' import { + defaultServerlessFunction, SnippetModel, SnippetType, SnippetTypeToLanguage, - defaultServerlessFunction, } from '../../../../models/snippet' import { CodeEditorForSnippet } from '../components/code-editor' import { InstallDependencyButton } from '../components/install-dep-button' diff --git a/src/views/extra-features/webhook/index.tsx b/src/views/extra-features/webhook/index.tsx index 192a30ba4..bdfa7dcde 100644 --- a/src/views/extra-features/webhook/index.tsx +++ b/src/views/extra-features/webhook/index.tsx @@ -1,4 +1,4 @@ -import { cloneDeep } from 'lodash-es' +import { cloneDeep } from 'es-toolkit/compat' import { NButton, NButtonGroup, diff --git a/src/views/maintenance/pty/index.tsx b/src/views/maintenance/pty/index.tsx index 89a0a5a09..65ce1ff09 100644 --- a/src/views/maintenance/pty/index.tsx +++ b/src/views/maintenance/pty/index.tsx @@ -1,10 +1,4 @@ -import { GATEWAY_URL } from '~/constants/env' -import { HeaderActionButton } from '~/components/button/rounded-button' -import { RefreshIcon, StatusIcon } from '~/components/icons' -import { IpInfoPopover } from '~/components/ip-info' -import { Xterm } from '~/components/xterm' -import { ContentLayout } from '~/layouts/content' -import { merge } from 'lodash-es' +import { merge } from 'es-toolkit/compat' import { NButton, NCard, @@ -16,13 +10,20 @@ import { useMessage, } from 'naive-ui' import Io from 'socket.io-client' -import { EventTypes } from '~/socket/types' -import { RESTManager, getToken, parseDate } from '~/utils' -import { bus } from '~/utils/event-bus' -import { useMountAndUnmount } from '~/hooks/use-lifecycle' import type { IDisposable, Terminal } from '@xterm/xterm' import type { PropType } from 'vue' +import { HeaderActionButton } from '~/components/button/rounded-button' +import { RefreshIcon, StatusIcon } from '~/components/icons' +import { IpInfoPopover } from '~/components/ip-info' +import { Xterm } from '~/components/xterm' +import { GATEWAY_URL } from '~/constants/env' +import { useMountAndUnmount } from '~/hooks/use-lifecycle' +import { ContentLayout } from '~/layouts/content' +import { EventTypes } from '~/socket/types' +import { getToken, parseDate, RESTManager } from '~/utils' +import { bus } from '~/utils/event-bus' + export default defineComponent({ name: 'PtyView', setup() { diff --git a/src/views/manage-notes/write.tsx b/src/views/manage-notes/write.tsx index 1f0a1a61d..7818a9a5c 100644 --- a/src/views/manage-notes/write.tsx +++ b/src/views/manage-notes/write.tsx @@ -1,5 +1,5 @@ import { add } from 'date-fns' -import { isString } from 'lodash-es' +import { isString } from 'es-toolkit/compat' import { NButton, NButtonGroup, diff --git a/src/views/manage-pages/write.tsx b/src/views/manage-pages/write.tsx index 17bd5cd9e..e3e5e7c6d 100644 --- a/src/views/manage-pages/write.tsx +++ b/src/views/manage-pages/write.tsx @@ -1,4 +1,4 @@ -import { isString } from 'lodash-es' +import { isString } from 'es-toolkit/compat' import { NFormItem, NInputNumber, useMessage } from 'naive-ui' import { computed, defineComponent, onMounted, reactive, ref, toRaw } from 'vue' import { useRoute, useRouter } from 'vue-router' diff --git a/src/views/manage-posts/write.tsx b/src/views/manage-posts/write.tsx index bdf633159..737715d54 100644 --- a/src/views/manage-posts/write.tsx +++ b/src/views/manage-posts/write.tsx @@ -1,4 +1,4 @@ -import { isString } from 'lodash-es' +import { isString } from 'es-toolkit/compat' import { NDynamicTags, NFormItem, diff --git a/src/views/manage-project/edit.tsx b/src/views/manage-project/edit.tsx index 541ffd040..b12d25519 100644 --- a/src/views/manage-project/edit.tsx +++ b/src/views/manage-project/edit.tsx @@ -1,17 +1,19 @@ +import { isString } from 'es-toolkit/compat' +import transform from 'lodash.transform' +import { NDynamicTags, NForm, NFormItem, NInput } from 'naive-ui' +import { computed, defineComponent, onMounted, reactive, toRaw } from 'vue' +import { useRoute, useRouter } from 'vue-router' +import type { IGithubRepo } from '~/external/api/github-repo' +import type { ProjectModel } from '~/models/project' + import { HeaderActionButton } from '~/components/button/rounded-button' +import { Editor } from '~/components/editor/universal' import { SendIcon } from '~/components/icons' import { FetchGithubRepoButton } from '~/components/special-button/fetch-github-repo' import { useParsePayloadIntoData } from '~/hooks/use-parse-payload' import { ContentLayout } from '~/layouts/content' -import { isString, transform } from 'lodash-es' -import { NDynamicTags, NForm, NFormItem, NInput } from 'naive-ui' import { RouteName } from '~/router/name' import { RESTManager } from '~/utils' -import { computed, defineComponent, onMounted, reactive, toRaw } from 'vue' -import { useRoute, useRouter } from 'vue-router' -import { Editor } from '~/components/editor/universal' -import type { IGithubRepo } from '~/external/api/github-repo' -import type { ProjectModel } from '~/models/project' type ProjectReactiveType = { name: string diff --git a/src/views/manage-says/edit.tsx b/src/views/manage-says/edit.tsx index 281178093..1593ad0dc 100644 --- a/src/views/manage-says/edit.tsx +++ b/src/views/manage-says/edit.tsx @@ -1,12 +1,6 @@ -import { HeaderActionButton } from '~/components/button/rounded-button' -import { CommentIcon, SendIcon } from '~/components/icons' -import { SentenceType, fetchHitokoto } from '~/external/api/hitokoto' -import { useParsePayloadIntoData } from '~/hooks/use-parse-payload' -import { ContentLayout } from '~/layouts/content' -import { isString, transform } from 'lodash-es' +import { isString } from 'es-toolkit/compat' +import transform from 'lodash.transform' import { NForm, NFormItem, NInput, useDialog } from 'naive-ui' -import { RouteName } from '~/router/name' -import { RESTManager } from '~/utils' import { computed, defineComponent, @@ -19,6 +13,14 @@ import { import { useRoute, useRouter } from 'vue-router' import type { SayModel } from '~/models/say' +import { HeaderActionButton } from '~/components/button/rounded-button' +import { CommentIcon, SendIcon } from '~/components/icons' +import { fetchHitokoto, SentenceType } from '~/external/api/hitokoto' +import { useParsePayloadIntoData } from '~/hooks/use-parse-payload' +import { ContentLayout } from '~/layouts/content' +import { RouteName } from '~/router/name' +import { RESTManager } from '~/utils' + type SayReactiveType = { text: string source: string diff --git a/src/views/setting/tabs/system.tsx b/src/views/setting/tabs/system.tsx index c6f48b5cb..ddc4892e8 100644 --- a/src/views/setting/tabs/system.tsx +++ b/src/views/setting/tabs/system.tsx @@ -1,4 +1,4 @@ -import { camelCase, cloneDeep, isEmpty, merge } from 'lodash-es' +import { camelCase, cloneDeep, isEmpty, merge } from 'es-toolkit/compat' import { NButton, NColorPicker, NFormItem, useThemeVars } from 'naive-ui' import { ThemeColorConfig } from 'theme.config' import { diff --git a/src/views/setting/tabs/user.tsx b/src/views/setting/tabs/user.tsx index b22a0f898..63793e250 100644 --- a/src/views/setting/tabs/user.tsx +++ b/src/views/setting/tabs/user.tsx @@ -1,10 +1,4 @@ -import { socialKeyMap } from '~/constants/social' -import Avatar from '~/components/avatar' -import { IpInfoPopover } from '~/components/ip-info' -import { KVEditor } from '~/components/kv-editor' -import { RelativeTime } from '~/components/time/relative-time' -import { UploadWrapper } from '~/components/upload' -import { cloneDeep, isEmpty } from 'lodash-es' +import { cloneDeep, isEmpty } from 'es-toolkit/compat' import { NButton, NForm, @@ -16,11 +10,19 @@ import { NUploadDragger, useMessage, } from 'naive-ui' -import { RESTManager, deepDiff } from '~/utils' import { computed, defineComponent, onMounted, ref } from 'vue' -import styles from './user.module.css' import type { UserModel } from '~/models/user' +import Avatar from '~/components/avatar' +import { IpInfoPopover } from '~/components/ip-info' +import { KVEditor } from '~/components/kv-editor' +import { RelativeTime } from '~/components/time/relative-time' +import { UploadWrapper } from '~/components/upload' +import { socialKeyMap } from '~/constants/social' +import { deepDiff, RESTManager } from '~/utils' + +import styles from './user.module.css' + export const TabUser = defineComponent(() => { const data = ref({} as UserModel) let origin: UserModel @@ -61,7 +63,7 @@ export const TabUser = defineComponent(() => { yGap={20} > - +