Skip to content

Commit

Permalink
refactor: package chart-ui integrated into plugins (#4238)
Browse files Browse the repository at this point in the history
* refactor: package chart-ui integrated into plugins

* fix: lint error
  • Loading branch information
anncwb authored Aug 26, 2024
1 parent fd7b347 commit 8a0b1e0
Show file tree
Hide file tree
Showing 37 changed files with 177 additions and 79 deletions.
2 changes: 1 addition & 1 deletion apps/web-antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
2 changes: 1 addition & 1 deletion apps/web-ele/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
2 changes: 1 addition & 1 deletion apps/web-naive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/en/guide/project/dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The directory uses Monorepo management, and the project structure is as follows:
│   ├── constants # Constants
│   ├── effects # Effects related packages
│   │   ├── access # Access control
│   │   ├── chart-ui # Chart UI
│   │   ├── plugins # Plugins
│   │   ├── common-ui # Common UI
│   │   ├── hooks # Composable APIs
│   │   ├── layouts # Layouts
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guide/project/dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
│   ├── constants # 常量
│   ├── effects # 副作用相关包
│   │   ├── access # 访问控制
│   │   ├── chart-ui # 图表 UI
│   │   ├── plugins # 第三方大型依赖插件
│   │   ├── common-ui # 通用 UI
│   │   ├── hooks # 组合式 API
│   │   ├── layouts # 布局
Expand Down
1 change: 0 additions & 1 deletion packages/effects/chart-ui/src/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/effects/plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @vben/plugins

该目录用于存放项目中集成的第三方库及其相关插件。每个插件都包含了可重用的逻辑、配置和组件,方便在项目中进行统一管理和调用。

## 注意

所有的第三方插件都必须以 `subpath` 形式引入,例:

`echarts` 为例,引入方式如下:

**packages.json**

```json
"exports": {
"./echarts": {
"types": "./src/echarts/index.ts",
"default": "./src/echarts/index.ts"
}
}
```

**使用方式**

```ts
import { useEcharts } from '@vben/plugins/echarts';
```

这样做的好处是,应用可以自行选择是否使用插件,而不会因为插件的引入及副作用而导致打包体积增大,只引入需要的插件即可。
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "@vben/chart-ui",
"name": "@vben/plugins",
"version": "5.1.2",
"homepage": "https://github.com/vbenjs/vue-vben-admin",
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/vbenjs/vue-vben-admin.git",
"directory": "packages/effects/chart-ui"
"directory": "packages/effects/plugins"
},
"license": "MIT",
"type": "module",
"sideEffects": [
"**/*.css"
],
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
"./echarts": {
"types": "./src/echarts/index.ts",
"default": "./src/echarts/index.ts"
}
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import type EchartsUI from './echarts-ui.vue';
import type { Ref } from 'vue';
import { computed, nextTick, watch } from 'vue';

import { preferences, usePreferences } from '@vben/preferences';
import { usePreferences } from '@vben/preferences';

import {
tryOnUnmounted,
useDebounceFn,
useResizeObserver,
useTimeoutFn,
useWindowSize,
} from '@vueuse/core';
Expand Down Expand Up @@ -86,6 +87,8 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
resizeHandler?.();
});

useResizeObserver(chartRef as never, resizeHandler);

watch(isDark, () => {
if (chartInstance) {
chartInstance.dispose();
Expand All @@ -95,21 +98,6 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
}
});

watch(
[
() => preferences.sidebar.collapsed,
() => preferences.sidebar.extraCollapse,
() => preferences.sidebar.hidden,
() => preferences.app.contentCompact,
],
() => {
// 折叠动画200ms
setTimeout(() => {
resize();
}, 200);
},
);

tryOnUnmounted(() => {
// 销毁实例,释放资源
chartInstance?.dispose();
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/utils/src/helpers/get-popup-container.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Returns the parent node of the given element or the document body if the element is not provided.it
*/
export function getPopupContainer(node?: HTMLElement): HTMLElement {
return (node?.parentNode as HTMLElement) ?? document.body;
}
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"dependencies": {
"@vben/access": "workspace:*",
"@vben/chart-ui": "workspace:*",
"@vben/common-ui": "workspace:*",
"@vben/constants": "workspace:*",
"@vben/hooks": "workspace:*",
"@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/plugins": "workspace:*",
"@vben/preferences": "workspace:*",
"@vben/request": "workspace:*",
"@vben/stores": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { EchartsUI, type EchartsUIType, useEcharts } from '@vben/chart-ui';
import {
EchartsUI,
type EchartsUIType,
useEcharts,
} from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
Expand Down
Loading

0 comments on commit 8a0b1e0

Please sign in to comment.