From 0faf7810b6da613535c44498dabe1549dc60bb56 Mon Sep 17 00:00:00 2001 From: Vben Date: Fri, 16 Aug 2024 22:20:18 +0800 Subject: [PATCH] perf: optimization of tabbar display (#4169) * perf: optimization of tabbar display * fix: ci error * chore: typo * chore: typo --- apps/web-antd/package.json | 4 +- apps/web-ele/package.json | 4 +- apps/web-naive/package.json | 4 +- docs/package.json | 2 +- .../eslint-config/src/configs/typescript.ts | 3 +- package.json | 2 +- packages/@core/base/icons/package.json | 4 +- packages/@core/base/shared/package.json | 2 +- packages/@core/base/typings/package.json | 2 +- packages/@core/base/typings/src/helper.d.ts | 35 +-- packages/@core/composables/package.json | 4 +- .../composables/src/use-content-style.ts | 18 +- .../composables/src/use-sortable.test.ts | 2 +- .../@core/composables/src/use-sortable.ts | 2 +- packages/@core/preferences/package.json | 4 +- packages/@core/ui-kit/layout-ui/package.json | 4 +- packages/@core/ui-kit/menu-ui/package.json | 4 +- packages/@core/ui-kit/shadcn-ui/package.json | 6 +- .../src/components/scrollbar/scrollbar.vue | 76 +++++- packages/@core/ui-kit/tabs-ui/package.json | 3 +- .../src/components/tabs-chrome/tabs.vue | 258 +++++++----------- .../tabs-ui/src/components/tabs/tabs.vue | 158 +++++------ .../@core/ui-kit/tabs-ui/src/tabs-view.vue | 170 ++++-------- packages/@core/ui-kit/tabs-ui/src/types.ts | 13 +- .../@core/ui-kit/tabs-ui/src/use-tabs-drag.ts | 110 ++++++++ .../tabs-ui/src/use-tabs-view-scroll.ts | 160 ++++++++++- packages/effects/access/package.json | 2 +- packages/effects/chart-ui/package.json | 4 +- packages/effects/common-ui/package.json | 4 +- packages/effects/hooks/package.json | 2 +- packages/effects/layouts/package.json | 4 +- packages/locales/package.json | 2 +- packages/stores/package.json | 2 +- packages/stores/src/modules/tabbar.ts | 17 +- packages/types/package.json | 2 +- playground/package.json | 4 +- playground/src/router/routes/modules/demos.ts | 2 +- pnpm-lock.yaml | 115 +++++--- 38 files changed, 710 insertions(+), 504 deletions(-) create mode 100644 packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts diff --git a/apps/web-antd/package.json b/apps/web-antd/package.json index 70827b2f..f3877755 100644 --- a/apps/web-antd/package.json +++ b/apps/web-antd/package.json @@ -40,11 +40,11 @@ "@vben/styles": "workspace:*", "@vben/types": "workspace:*", "@vben/utils": "workspace:*", - "@vueuse/core": "^10.11.1", + "@vueuse/core": "^11.0.0", "ant-design-vue": "^4.2.3", "dayjs": "^1.11.12", "pinia": "2.2.2", - "vue": "^3.4.38", + "vue": "^3.4.37", "vue-router": "^4.4.3" } } diff --git a/apps/web-ele/package.json b/apps/web-ele/package.json index bc70f0d4..f16e39ba 100644 --- a/apps/web-ele/package.json +++ b/apps/web-ele/package.json @@ -40,11 +40,11 @@ "@vben/styles": "workspace:*", "@vben/types": "workspace:*", "@vben/utils": "workspace:*", - "@vueuse/core": "^10.11.1", + "@vueuse/core": "^11.0.0", "dayjs": "^1.11.12", "element-plus": "^2.8.0", "pinia": "2.2.2", - "vue": "^3.4.38", + "vue": "^3.4.37", "vue-router": "^4.4.3" }, "devDependencies": { diff --git a/apps/web-naive/package.json b/apps/web-naive/package.json index 09aad2e5..a4e73e0c 100644 --- a/apps/web-naive/package.json +++ b/apps/web-naive/package.json @@ -40,10 +40,10 @@ "@vben/styles": "workspace:*", "@vben/types": "workspace:*", "@vben/utils": "workspace:*", - "@vueuse/core": "^10.11.1", + "@vueuse/core": "^11.0.0", "naive-ui": "^2.39.0", "pinia": "2.2.2", - "vue": "^3.4.38", + "vue": "^3.4.37", "vue-router": "^4.4.3" } } diff --git a/docs/package.json b/docs/package.json index 784f9488..e7b2882d 100644 --- a/docs/package.json +++ b/docs/package.json @@ -14,6 +14,6 @@ "@nolebase/vitepress-plugin-git-changelog": "^2.4.0", "@vite-pwa/vitepress": "^0.5.0", "vitepress": "^1.3.2", - "vue": "^3.4.38" + "vue": "^3.4.37" } } diff --git a/internal/lint-configs/eslint-config/src/configs/typescript.ts b/internal/lint-configs/eslint-config/src/configs/typescript.ts index a97f0c04..0ac12df5 100644 --- a/internal/lint-configs/eslint-config/src/configs/typescript.ts +++ b/internal/lint-configs/eslint-config/src/configs/typescript.ts @@ -42,7 +42,8 @@ export async function typescript(): Promise { }, ], - '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], + // '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], + '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-empty-function': [ diff --git a/package.json b/package.json index 172c0be6..0f646997 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ "node": ">=20", "pnpm": ">=9" }, - "packageManager": "pnpm@9.7.0", + "packageManager": "pnpm@9.7.1", "pnpm": { "peerDependencyRules": { "allowedVersions": { diff --git a/packages/@core/base/icons/package.json b/packages/@core/base/icons/package.json index 3ea351d9..44d43335 100644 --- a/packages/@core/base/icons/package.json +++ b/packages/@core/base/icons/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "@iconify/vue": "^4.1.2", - "lucide-vue-next": "^0.427.0", - "vue": "^3.4.38" + "lucide-vue-next": "^0.428.0", + "vue": "^3.4.37" } } diff --git a/packages/@core/base/shared/package.json b/packages/@core/base/shared/package.json index 2ee23ea0..cc4d490f 100644 --- a/packages/@core/base/shared/package.json +++ b/packages/@core/base/shared/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@ctrl/tinycolor": "^4.1.0", - "@vue/shared": "^3.4.38", + "@vue/shared": "^3.4.37", "clsx": "^2.1.1", "defu": "^6.1.4", "lodash.clonedeep": "^4.5.0", diff --git a/packages/@core/base/typings/package.json b/packages/@core/base/typings/package.json index 590e874d..47d2d78c 100644 --- a/packages/@core/base/typings/package.json +++ b/packages/@core/base/typings/package.json @@ -38,7 +38,7 @@ } }, "dependencies": { - "vue": "^3.4.38", + "vue": "^3.4.37", "vue-router": "^4.4.3" } } diff --git a/packages/@core/base/typings/src/helper.d.ts b/packages/@core/base/typings/src/helper.d.ts index fdc85edf..8a6385b4 100644 --- a/packages/@core/base/typings/src/helper.d.ts +++ b/packages/@core/base/typings/src/helper.d.ts @@ -107,20 +107,23 @@ type MergeAll< ? MergeAll> : R; -export { - type AnyFunction, - type AnyNormalFunction, - type AnyPromiseFunction, - type DeepPartial, - type DeepReadonly, - type IntervalHandle, - type MaybeComputedRef, - type MaybeReadonlyRef, - type Merge, - type MergeAll, - type NonNullable, - type Nullable, - type ReadonlyRecordable, - type Recordable, - type TimeoutHandle, +type EmitType = (name: Name, ...args: any[]) => void; + +export type { + AnyFunction, + AnyNormalFunction, + AnyPromiseFunction, + DeepPartial, + DeepReadonly, + EmitType, + IntervalHandle, + MaybeComputedRef, + MaybeReadonlyRef, + Merge, + MergeAll, + NonNullable, + Nullable, + ReadonlyRecordable, + Recordable, + TimeoutHandle, }; diff --git a/packages/@core/composables/package.json b/packages/@core/composables/package.json index 82c67362..e8485016 100644 --- a/packages/@core/composables/package.json +++ b/packages/@core/composables/package.json @@ -36,10 +36,10 @@ }, "dependencies": { "@vben-core/shared": "workspace:*", - "@vueuse/core": "^10.11.1", + "@vueuse/core": "^11.0.0", "radix-vue": "^1.9.4", "sortablejs": "^1.15.2", - "vue": "^3.4.38" + "vue": "^3.4.37" }, "devDependencies": { "@types/sortablejs": "^1.15.8" diff --git a/packages/@core/composables/src/use-content-style.ts b/packages/@core/composables/src/use-content-style.ts index 7c9b777c..94aa2148 100644 --- a/packages/@core/composables/src/use-content-style.ts +++ b/packages/@core/composables/src/use-content-style.ts @@ -1,5 +1,5 @@ import type { CSSProperties } from 'vue'; -import { computed, nextTick, onMounted, ref } from 'vue'; +import { computed, onMounted, onUnmounted, ref } from 'vue'; import { CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT, @@ -14,6 +14,7 @@ import { useCssVar, useDebounceFn } from '@vueuse/core'; * @zh_CN content style */ function useContentStyle() { + let resizeObserver: null | ResizeObserver = null; const contentElement = ref(null); const visibleDomRect = ref(null); const contentHeight = useCssVar(CSS_VARIABLE_LAYOUT_CONTENT_HEIGHT); @@ -41,12 +42,15 @@ function useContentStyle() { ); onMounted(() => { - nextTick(() => { - if (contentElement.value) { - const observer = new ResizeObserver(debouncedCalcHeight); - observer.observe(contentElement.value); - } - }); + if (contentElement.value && !resizeObserver) { + resizeObserver = new ResizeObserver(debouncedCalcHeight); + resizeObserver.observe(contentElement.value); + } + }); + + onUnmounted(() => { + resizeObserver?.disconnect(); + resizeObserver = null; }); return { contentElement, overlayStyle, visibleDomRect }; diff --git a/packages/@core/composables/src/use-sortable.test.ts b/packages/@core/composables/src/use-sortable.test.ts index 6210bb47..70aa2234 100644 --- a/packages/@core/composables/src/use-sortable.test.ts +++ b/packages/@core/composables/src/use-sortable.test.ts @@ -39,7 +39,7 @@ describe('useSortable', () => { expect(Sortable.default.create).toHaveBeenCalledWith( mockElement, expect.objectContaining({ - animation: 100, + animation: 300, delay: 400, delayOnTouchOnly: true, ...customOptions, diff --git a/packages/@core/composables/src/use-sortable.ts b/packages/@core/composables/src/use-sortable.ts index 527226fd..6659db83 100644 --- a/packages/@core/composables/src/use-sortable.ts +++ b/packages/@core/composables/src/use-sortable.ts @@ -18,7 +18,7 @@ function useSortable( // Sortable?.default?.mount?.(AutoScroll); const sortable = Sortable?.default?.create?.(sortableContainer, { - animation: 100, + animation: 300, delay: 400, delayOnTouchOnly: true, ...options, diff --git a/packages/@core/preferences/package.json b/packages/@core/preferences/package.json index 618381ec..2e043696 100644 --- a/packages/@core/preferences/package.json +++ b/packages/@core/preferences/package.json @@ -31,7 +31,7 @@ "dependencies": { "@vben-core/shared": "workspace:*", "@vben-core/typings": "workspace:*", - "@vueuse/core": "^10.11.1", - "vue": "^3.4.38" + "@vueuse/core": "^11.0.0", + "vue": "^3.4.37" } } diff --git a/packages/@core/ui-kit/layout-ui/package.json b/packages/@core/ui-kit/layout-ui/package.json index fb532533..c0dd5f63 100644 --- a/packages/@core/ui-kit/layout-ui/package.json +++ b/packages/@core/ui-kit/layout-ui/package.json @@ -41,7 +41,7 @@ "@vben-core/icons": "workspace:*", "@vben-core/shadcn-ui": "workspace:*", "@vben-core/typings": "workspace:*", - "@vueuse/core": "^10.11.1", - "vue": "^3.4.38" + "@vueuse/core": "^11.0.0", + "vue": "^3.4.37" } } diff --git a/packages/@core/ui-kit/menu-ui/package.json b/packages/@core/ui-kit/menu-ui/package.json index 623db979..c452f05c 100644 --- a/packages/@core/ui-kit/menu-ui/package.json +++ b/packages/@core/ui-kit/menu-ui/package.json @@ -42,7 +42,7 @@ "@vben-core/shadcn-ui": "workspace:*", "@vben-core/shared": "workspace:*", "@vben-core/typings": "workspace:*", - "@vueuse/core": "^10.11.1", - "vue": "^3.4.38" + "@vueuse/core": "^11.0.0", + "vue": "^3.4.37" } } diff --git a/packages/@core/ui-kit/shadcn-ui/package.json b/packages/@core/ui-kit/shadcn-ui/package.json index a2a7755c..69f96e00 100644 --- a/packages/@core/ui-kit/shadcn-ui/package.json +++ b/packages/@core/ui-kit/shadcn-ui/package.json @@ -46,10 +46,10 @@ "@vben-core/icons": "workspace:*", "@vben-core/shared": "workspace:*", "@vben-core/typings": "workspace:*", - "@vueuse/core": "^10.11.1", + "@vueuse/core": "^11.0.0", "class-variance-authority": "^0.7.0", - "lucide-vue-next": "^0.427.0", + "lucide-vue-next": "^0.428.0", "radix-vue": "^1.9.4", - "vue": "^3.4.38" + "vue": "^3.4.37" } } diff --git a/packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue b/packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue index fe612db4..b6444df0 100644 --- a/packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue +++ b/packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue @@ -1,5 +1,5 @@