@vtj/ui 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +4 -0
  2. package/lib/cdn/index.cjs.js +1 -0
  3. package/lib/cdn/index.es.js +242 -0
  4. package/lib/cdn/index.umd.js +1 -0
  5. package/lib/cdn/style.css +1 -0
  6. package/lib/index.cjs.js +1 -0
  7. package/lib/index.es.js +246 -0
  8. package/lib/index.umd.js +1 -0
  9. package/lib/style.css +1 -0
  10. package/package.json +55 -0
  11. package/src/components/XChart/Chart.vue +42 -0
  12. package/src/components/XChart/index.ts +8 -0
  13. package/src/components/XChart/style.scss +0 -0
  14. package/src/components/XChartBar/Bar.vue +27 -0
  15. package/src/components/XChartBar/index.ts +8 -0
  16. package/src/components/XChartLine/Line.vue +27 -0
  17. package/src/components/XChartLine/index.ts +8 -0
  18. package/src/components/XChartPie/Pie.vue +54 -0
  19. package/src/components/XChartPie/index.ts +8 -0
  20. package/src/components/XTestSuit/TestSuit.vue +47 -0
  21. package/src/components/XTestSuit/index.ts +8 -0
  22. package/src/components/XTestSuit/style.scss +14 -0
  23. package/src/hooks/useECharts.ts +55 -0
  24. package/src/hooks/useRectChart.ts +46 -0
  25. package/src/index.ts +23 -0
  26. package/src/theme/_vars.scss +8 -0
  27. package/src/theme/base.scss +0 -0
  28. package/src/theme/index.scss +4 -0
  29. package/types/dev/vite-env.d.ts +7 -0
  30. package/types/index.d.ts +4 -0
  31. package/types/src/components/XChart/Chart.vue.d.ts +69 -0
  32. package/types/src/components/XChart/index.d.ts +2 -0
  33. package/types/src/components/XChartBar/Bar.vue.d.ts +124 -0
  34. package/types/src/components/XChartBar/index.d.ts +2 -0
  35. package/types/src/components/XChartLine/Line.vue.d.ts +124 -0
  36. package/types/src/components/XChartLine/index.d.ts +2 -0
  37. package/types/src/components/XChartPie/Pie.vue.d.ts +111 -0
  38. package/types/src/components/XChartPie/index.d.ts +2 -0
  39. package/types/src/components/XTestSuit/TestSuit.vue.d.ts +59 -0
  40. package/types/src/components/XTestSuit/index.d.ts +2 -0
  41. package/types/src/hooks/useECharts.d.ts +15 -0
  42. package/types/src/hooks/useRectChart.d.ts +4 -0
  43. package/types/src/index.d.ts +6 -0
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <XChart :key="key" :optionFactory="optionFactory"></XChart>
3
+ </template>
4
+ <script lang="ts" setup>
5
+ import { XChart } from '@vtj/ui';
6
+ import useRectChart from '../../hooks/useRectChart';
7
+ export type ISourceType = Array<Record<string, any>>;
8
+
9
+ export type IOptionFactory = (
10
+ opt?: Record<string, any>
11
+ ) => Promise<Record<string, any>>;
12
+
13
+ export interface Props {
14
+ category?: 'x' | 'y';
15
+ dimensions?: string[];
16
+ source?: ISourceType | (() => Promise<ISourceType>);
17
+ optionFactory?: IOptionFactory;
18
+ }
19
+
20
+ const props = withDefaults(defineProps<Props>(), {
21
+ category: 'x',
22
+ dimensions: () => [],
23
+ source: () => []
24
+ });
25
+
26
+ const { optionFactory, key } = useRectChart(props, 'bar');
27
+ </script>
@@ -0,0 +1,8 @@
1
+ import Bar from './Bar.vue';
2
+ import { App } from 'vue';
3
+
4
+ Bar.install = function (app: App) {
5
+ app.component('XChartBar', Bar);
6
+ };
7
+
8
+ export default Bar;
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <XChart :key="key" :optionFactory="optionFactory"></XChart>
3
+ </template>
4
+ <script lang="ts" setup>
5
+ import { XChart } from '@vtj/ui';
6
+ import useRectChart from '../../hooks/useRectChart';
7
+ export type ISourceType = Array<Record<string, any>>;
8
+
9
+ export type IOptionFactory = (
10
+ opt?: Record<string, any>
11
+ ) => Promise<Record<string, any>>;
12
+
13
+ export interface Props {
14
+ category?: 'x' | 'y';
15
+ dimensions?: string[];
16
+ source?: ISourceType | (() => Promise<ISourceType>);
17
+ optionFactory?: IOptionFactory;
18
+ }
19
+
20
+ const props = withDefaults(defineProps<Props>(), {
21
+ category: 'x',
22
+ dimensions: () => [],
23
+ source: () => []
24
+ });
25
+
26
+ const { optionFactory, key } = useRectChart(props, 'line');
27
+ </script>
@@ -0,0 +1,8 @@
1
+ import Line from './Line.vue';
2
+ import { App } from 'vue';
3
+
4
+ Line.install = function (app: App) {
5
+ app.component('XChartLine', Line);
6
+ };
7
+
8
+ export default Line;
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <XChart :key="key" :optionFactory="optionFactory"></XChart>
3
+ </template>
4
+ <script lang="ts" setup>
5
+ import { XChart } from '@vtj/ui';
6
+ import { merge } from '@vtj/utils';
7
+ import { ref, watch } from 'vue';
8
+ export type ISourceType = Array<Record<string, any>>;
9
+
10
+ export type IOptionFactory = (
11
+ opt?: Record<string, any>
12
+ ) => Promise<Record<string, any>>;
13
+
14
+ export interface Props {
15
+ dimensions?: string[];
16
+ source?: ISourceType | (() => Promise<ISourceType>);
17
+ optionFactory?: IOptionFactory;
18
+ }
19
+
20
+ const props = withDefaults(defineProps<Props>(), {
21
+ dimensions: () => [],
22
+ source: () => []
23
+ });
24
+
25
+ const key = ref(Symbol('key'));
26
+
27
+ const optionFactory = async (opts: any) => {
28
+ const option = {
29
+ ...opts,
30
+ dataset: {
31
+ dimensions: props.dimensions,
32
+ source:
33
+ typeof props.source === 'function' ? await props.source() : props.source
34
+ },
35
+ series: [
36
+ {
37
+ type: 'pie'
38
+ }
39
+ ]
40
+ };
41
+
42
+ return merge(
43
+ option,
44
+ props.optionFactory ? await props.optionFactory(option) : {}
45
+ );
46
+ };
47
+
48
+ watch(
49
+ () => [props.dimensions, props.source, props.optionFactory],
50
+ () => {
51
+ key.value = Symbol('key');
52
+ }
53
+ );
54
+ </script>
@@ -0,0 +1,8 @@
1
+ import Pie from './Pie.vue';
2
+ import { App } from 'vue';
3
+
4
+ Pie.install = function (app: App) {
5
+ app.component('XChartPie', Pie);
6
+ };
7
+
8
+ export default Pie;
@@ -0,0 +1,47 @@
1
+ <template>
2
+ <div class="x-test-suit">
3
+ <div class="x-test-suit__header">XTestSuit</div>
4
+ <div class="x-test-suit__body">
5
+ <div class="x-test-suit_props">
6
+ <div v-for="item in propList">
7
+ {{ item.name }}: {{ JSON.stringify(item.value) }}
8
+ </div>
9
+ </div>
10
+ <div class="x-test-suit_events">
11
+ <button @click="onClick">Tigger Click Event</button>
12
+ </div>
13
+ <div class="x-test-suit_slots">
14
+ <div>
15
+ <slot> Default Slot</slot>
16
+ </div>
17
+ <div v-if="$slots.footer">
18
+ <slot name="footer"></slot>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ </div>
23
+ </template>
24
+ <script lang="ts" setup>
25
+ import { computed } from 'vue';
26
+ export interface Props {
27
+ p1?: string;
28
+ p2?: number;
29
+ p3?: boolean;
30
+ p4?: any;
31
+ }
32
+ const props = withDefaults(defineProps<Props>(), {});
33
+ const emit = defineEmits(['click']);
34
+
35
+ const propList = computed(() => {
36
+ return [
37
+ { name: 'p1', value: props.p1 },
38
+ { name: 'p2', value: props.p2 },
39
+ { name: 'p3', value: props.p3 },
40
+ { name: 'p4', value: props.p4 }
41
+ ];
42
+ });
43
+
44
+ const onClick = () => {
45
+ emit('click');
46
+ };
47
+ </script>
@@ -0,0 +1,8 @@
1
+ import TestSuit from './TestSuit.vue';
2
+ import { App } from 'vue';
3
+
4
+ TestSuit.install = function (app: App) {
5
+ app.component('XTestSuit', TestSuit);
6
+ };
7
+
8
+ export default TestSuit;
@@ -0,0 +1,14 @@
1
+ .x-test-suit {
2
+ width: 100%;
3
+ height: 100%;
4
+ border: 1px solid #ccc;
5
+ &__header {
6
+ padding: 5px 10px;
7
+ background-color: #efefef;
8
+ }
9
+ &__body {
10
+ padding: 10px;
11
+ }
12
+ &__props {
13
+ }
14
+ }
@@ -0,0 +1,55 @@
1
+ import { Ref, ref, onMounted, watch } from 'vue';
2
+ import * as echarts from 'echarts';
3
+ import { useResizeObserver } from '@vueuse/core';
4
+ import { merge, debounce } from '@vtj/utils';
5
+
6
+ export type IOptionFactory = (
7
+ opt?: Record<string, any>
8
+ ) => Promise<Record<string, any>>;
9
+
10
+ export interface Props {
11
+ width?: string;
12
+ height?: string;
13
+ option?: Record<string, any>;
14
+ optionFactory?: IOptionFactory;
15
+ }
16
+
17
+ export default function (container: Ref, props: Props = {}) {
18
+ const done = ref(false);
19
+ let chart: any = null;
20
+ const init = async (opt?: Record<string, any>) => {
21
+ chart = echarts.init(container.value);
22
+ const option =
23
+ opt ||
24
+ merge(
25
+ {},
26
+ props.option,
27
+ props.optionFactory ? await props.optionFactory(props.option) : {}
28
+ );
29
+ chart.setOption(option);
30
+ };
31
+
32
+ const reset = () => {
33
+ chart?.dispose();
34
+ init();
35
+ };
36
+
37
+ const resize = debounce(() => {
38
+ if (!done.value) {
39
+ done.value = true;
40
+ return;
41
+ }
42
+ chart?.resize();
43
+ }, 100);
44
+
45
+ onMounted(init);
46
+
47
+ watch(() => [props.option, props.optionFactory], reset);
48
+ useResizeObserver(container, resize);
49
+ return {
50
+ getChart: () => chart,
51
+ echarts,
52
+ reset,
53
+ resize
54
+ };
55
+ }
@@ -0,0 +1,46 @@
1
+ import { merge } from '@vtj/utils';
2
+ import { ref, watch } from 'vue';
3
+ export default function (props: any, chartType: 'line' | 'bar') {
4
+ const optionFactory = async (opt?: Record<string, any>) => {
5
+ const option: Record<string, any> = {
6
+ ...opt,
7
+ title: {},
8
+ xAxis: {},
9
+ yAxis: {}
10
+ };
11
+ if (props.category === 'x') {
12
+ option.xAxis = { type: 'category' };
13
+ option.yAxis = {};
14
+ } else {
15
+ option.xAxis = {};
16
+ option.yAxis = { type: 'category' };
17
+ }
18
+ option.dataset = {
19
+ dimensions: props.dimensions,
20
+ source:
21
+ typeof props.source === 'function' ? await props.source() : props.source
22
+ };
23
+ const length = (props.dimensions || []).length;
24
+ if (length > 1) {
25
+ const series = new Array(length - 1);
26
+ series.fill({ type: chartType });
27
+ option.series = series;
28
+ }
29
+
30
+ return merge(
31
+ option,
32
+ props.optionFactory ? await props.optionFactory(option) : {}
33
+ );
34
+ };
35
+ const key = ref(Symbol('key'));
36
+ watch(
37
+ () => [props.category, props.dimensions, props.source, props.optionFactory],
38
+ () => {
39
+ key.value = Symbol('key');
40
+ }
41
+ );
42
+ return {
43
+ optionFactory,
44
+ key
45
+ };
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ import './theme/index.scss';
2
+ import { App } from 'vue';
3
+ import XTestSuit from './components/XTestSuit';
4
+ import XChart from './components/XChart';
5
+ import XChartBar from './components/XChartBar';
6
+ import XChartLine from './components/XChartLine';
7
+ import XChartPie from './components/XChartPie';
8
+
9
+ const components: Record<string, any> = {
10
+ XTestSuit,
11
+ XChart,
12
+ XChartBar,
13
+ XChartLine,
14
+ XChartPie
15
+ };
16
+
17
+ components.install = function (app: App) {
18
+ Object.keys(components).forEach((key) => {
19
+ app.component(key, components[key]);
20
+ });
21
+ };
22
+
23
+ export { XTestSuit, XChart, XChartBar, XChartLine, XChartPie };
@@ -0,0 +1,8 @@
1
+ $--color-primary: #409eff;
2
+ $--color-primary-dark: #337ecc;
3
+
4
+ $--white: #fff;
5
+ $--black: #000;
6
+
7
+ $--base-background: $--white;
8
+ $--page-background: #f2f3f5;
File without changes
@@ -0,0 +1,4 @@
1
+ @import './vars';
2
+ @import './base.scss';
3
+ @import '../components/XTestSuit/style.scss';
4
+ @import '../components/XChart/style.scss';
@@ -0,0 +1,7 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue';
5
+ const component: DefineComponent<{}, {}, any>;
6
+ export default component;
7
+ }
@@ -0,0 +1,4 @@
1
+ declare module '@vtj/ui' {
2
+ //@ts-ignore
3
+ export * from '@vtj/ui/types/src/index';
4
+ }
@@ -0,0 +1,69 @@
1
+ export declare type IOptionFactory = (opt?: Record<string, any>) => Promise<Record<string, any>>;
2
+ export interface Props {
3
+ width?: string;
4
+ height?: string;
5
+ option?: Record<string, any>;
6
+ optionFactory?: IOptionFactory;
7
+ }
8
+ declare const _sfc_main: import("vue").DefineComponent<{
9
+ width: {
10
+ type: StringConstructor;
11
+ required: false;
12
+ default: string;
13
+ };
14
+ height: {
15
+ type: StringConstructor;
16
+ required: false;
17
+ default: string;
18
+ };
19
+ option: {
20
+ type: ObjectConstructor;
21
+ required: false;
22
+ default: () => {};
23
+ };
24
+ optionFactory: {
25
+ type: FunctionConstructor;
26
+ required: false;
27
+ };
28
+ }, {
29
+ props: {
30
+ width: string;
31
+ height: string;
32
+ option: Record<string, any>;
33
+ optionFactory?: IOptionFactory | undefined;
34
+ };
35
+ container: import("vue").Ref<HTMLElement | undefined>;
36
+ style: import("vue").ComputedRef<{
37
+ width: string;
38
+ height: string;
39
+ }>;
40
+ getChart: () => any;
41
+ reset: () => void;
42
+ resize: import("lodash").DebouncedFunc<() => void>;
43
+ echarts: typeof import("echarts/types/dist/echarts");
44
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
45
+ width: {
46
+ type: StringConstructor;
47
+ required: false;
48
+ default: string;
49
+ };
50
+ height: {
51
+ type: StringConstructor;
52
+ required: false;
53
+ default: string;
54
+ };
55
+ option: {
56
+ type: ObjectConstructor;
57
+ required: false;
58
+ default: () => {};
59
+ };
60
+ optionFactory: {
61
+ type: FunctionConstructor;
62
+ required: false;
63
+ };
64
+ }>>, {
65
+ width: string;
66
+ height: string;
67
+ option: Record<string, any>;
68
+ }>;
69
+ export default _sfc_main;
@@ -0,0 +1,2 @@
1
+ import Chart from './Chart.vue';
2
+ export default Chart;
@@ -0,0 +1,124 @@
1
+ export declare type ISourceType = Array<Record<string, any>>;
2
+ export declare type IOptionFactory = (opt?: Record<string, any>) => Promise<Record<string, any>>;
3
+ export interface Props {
4
+ category?: 'x' | 'y';
5
+ dimensions?: string[];
6
+ source?: ISourceType | (() => Promise<ISourceType>);
7
+ optionFactory?: IOptionFactory;
8
+ }
9
+ declare const _sfc_main: import("vue").DefineComponent<{
10
+ category: {
11
+ type: StringConstructor;
12
+ required: false;
13
+ default: string;
14
+ };
15
+ dimensions: {
16
+ type: ArrayConstructor;
17
+ required: false;
18
+ default: () => never[];
19
+ };
20
+ source: {
21
+ type: (FunctionConstructor | ArrayConstructor)[];
22
+ required: false;
23
+ default: () => never[];
24
+ };
25
+ optionFactory: {
26
+ type: FunctionConstructor;
27
+ required: false;
28
+ };
29
+ }, {
30
+ props: {
31
+ category: 'x' | 'y';
32
+ dimensions: string[];
33
+ source: ISourceType | (() => Promise<ISourceType>);
34
+ optionFactory?: IOptionFactory | undefined;
35
+ };
36
+ optionFactory: (opt?: Record<string, any> | undefined) => Promise<any>;
37
+ key: import("vue").Ref<symbol>;
38
+ XChart: import("vue").DefineComponent<{
39
+ width: {
40
+ type: StringConstructor;
41
+ required: false;
42
+ default: string;
43
+ };
44
+ height: {
45
+ type: StringConstructor;
46
+ required: false;
47
+ default: string;
48
+ };
49
+ option: {
50
+ type: ObjectConstructor;
51
+ required: false;
52
+ default: () => {};
53
+ };
54
+ optionFactory: {
55
+ type: FunctionConstructor;
56
+ required: false;
57
+ };
58
+ }, {
59
+ props: {
60
+ width: string;
61
+ height: string;
62
+ option: Record<string, any>;
63
+ optionFactory?: import("../XChart/Chart.vue").IOptionFactory | undefined;
64
+ };
65
+ container: import("vue").Ref<HTMLElement | undefined>;
66
+ style: import("vue").ComputedRef<{
67
+ width: string;
68
+ height: string;
69
+ }>;
70
+ getChart: () => any;
71
+ reset: () => void;
72
+ resize: import("lodash").DebouncedFunc<() => void>;
73
+ echarts: typeof import("echarts/types/dist/echarts");
74
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
75
+ width: {
76
+ type: StringConstructor;
77
+ required: false;
78
+ default: string;
79
+ };
80
+ height: {
81
+ type: StringConstructor;
82
+ required: false;
83
+ default: string;
84
+ };
85
+ option: {
86
+ type: ObjectConstructor;
87
+ required: false;
88
+ default: () => {};
89
+ };
90
+ optionFactory: {
91
+ type: FunctionConstructor;
92
+ required: false;
93
+ };
94
+ }>>, {
95
+ width: string;
96
+ height: string;
97
+ option: Record<string, any>;
98
+ }>;
99
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
100
+ category: {
101
+ type: StringConstructor;
102
+ required: false;
103
+ default: string;
104
+ };
105
+ dimensions: {
106
+ type: ArrayConstructor;
107
+ required: false;
108
+ default: () => never[];
109
+ };
110
+ source: {
111
+ type: (FunctionConstructor | ArrayConstructor)[];
112
+ required: false;
113
+ default: () => never[];
114
+ };
115
+ optionFactory: {
116
+ type: FunctionConstructor;
117
+ required: false;
118
+ };
119
+ }>>, {
120
+ category: string;
121
+ dimensions: unknown[];
122
+ source: Function | unknown[];
123
+ }>;
124
+ export default _sfc_main;
@@ -0,0 +1,2 @@
1
+ import Bar from './Bar.vue';
2
+ export default Bar;