@tmagic/table 1.3.0-alpha.2 → 1.3.0-alpha.21

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-alpha.2",
2
+ "version": "1.3.0-alpha.21",
3
3
  "name": "@tmagic/table",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -33,28 +33,27 @@
33
33
  "url": "https://github.com/Tencent/tmagic-editor.git"
34
34
  },
35
35
  "dependencies": {
36
- "@tmagic/design": "1.3.0-alpha.2",
37
- "@tmagic/form": "1.3.0-alpha.2",
38
- "@tmagic/utils": "1.3.0-alpha.2",
36
+ "@tmagic/design": "1.3.0-alpha.21",
37
+ "@tmagic/form": "1.3.0-alpha.21",
38
+ "@tmagic/utils": "1.3.0-alpha.21",
39
39
  "lodash-es": "^4.17.21",
40
- "vue": "^3.2.37"
40
+ "vue": "^3.3.4"
41
41
  },
42
42
  "peerDependencies": {
43
- "@tmagic/form": "1.3.0-alpha.2",
44
- "vue": "^3.2.37"
43
+ "@tmagic/form": "1.3.0-alpha.21",
44
+ "vue": "^3.3.4"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/color": "^3.0.1",
48
48
  "@types/lodash-es": "^4.17.4",
49
49
  "@types/node": "^15.12.4",
50
- "@vitejs/plugin-vue": "^4.1.0",
51
- "@vue/compiler-sfc": "^3.2.37",
52
- "@vue/test-utils": "^2.0.0",
50
+ "@vitejs/plugin-vue": "^4.2.3",
51
+ "@vue/compiler-sfc": "^3.3.4",
52
+ "@vue/test-utils": "^2.3.2",
53
53
  "rimraf": "^3.0.2",
54
54
  "sass": "^1.35.1",
55
55
  "typescript": "^5.0.4",
56
- "vite": "^4.2.1",
57
- "vite-plugin-vue-setup-extend": "^0.4.0",
58
- "vue-tsc": "^1.2.0"
56
+ "vite": "^4.4.4",
57
+ "vue-tsc": "^1.6.5"
59
58
  }
60
59
  }
@@ -1,18 +1,24 @@
1
1
  <template>
2
2
  <TMagicTableColumn :label="config.label" :width="config.width" :fixed="config.fixed">
3
3
  <template v-slot="scope">
4
- <TMagicButton
4
+ <TMagicTooltip
5
5
  v-for="(action, actionIndex) in config.actions"
6
- v-show="display(action.display, scope.row) && !editState[scope.$index]"
7
- class="action-btn"
8
- text
9
- :type="action.buttonType || 'primary'"
10
- size="small"
11
- :icon="action.icon"
6
+ :placement="action.tooltipPlacement || 'top'"
12
7
  :key="actionIndex"
13
- @click="actionHandler(action, scope.row, scope.$index)"
14
- ><span v-html="formatter(action.text, scope.row)"></span
15
- ></TMagicButton>
8
+ :disabled="!Boolean(action.tooltip)"
9
+ :content="action.tooltip"
10
+ >
11
+ <TMagicButton
12
+ v-show="display(action.display, scope.row) && !editState[scope.$index]"
13
+ class="action-btn"
14
+ text
15
+ size="small"
16
+ :type="action.buttonType || 'primary'"
17
+ :icon="action.icon"
18
+ @click="actionHandler(action, scope.row, scope.$index)"
19
+ ><span v-html="formatter(action.text, scope.row)"></span
20
+ ></TMagicButton>
21
+ </TMagicTooltip>
16
22
  <TMagicButton
17
23
  class="action-btn"
18
24
  v-show="editState[scope.$index]"
@@ -35,11 +41,15 @@
35
41
  </TMagicTableColumn>
36
42
  </template>
37
43
 
38
- <script lang="ts" setup name="MTableActionsColumn">
39
- import { TMagicButton, tMagicMessage, TMagicTableColumn } from '@tmagic/design';
44
+ <script lang="ts" setup>
45
+ import { TMagicButton, tMagicMessage, TMagicTableColumn, TMagicTooltip } from '@tmagic/design';
40
46
 
41
47
  import { ColumnActionConfig, ColumnConfig } from './schema';
42
48
 
49
+ defineOptions({
50
+ name: 'MTableActionsColumn',
51
+ });
52
+
43
53
  const props = withDefaults(
44
54
  defineProps<{
45
55
  columns: any[];
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <TMagicTableColumn
3
+ show-overflow-tooltip
4
+ :label="config.label"
5
+ :width="config.width"
6
+ :fixed="config.fixed"
7
+ :sortable="config.sortable"
8
+ :prop="config.prop"
9
+ >
10
+ <template v-slot="scope">
11
+ <component :is="config.component" v-bind="componentProps(scope.row)"></component>
12
+ </template>
13
+ </TMagicTableColumn>
14
+ </template>
15
+
16
+ <script lang="ts" setup>
17
+ import { TMagicTableColumn } from '@tmagic/design';
18
+
19
+ import { ColumnConfig } from './schema';
20
+
21
+ defineOptions({
22
+ name: 'MTableColumn',
23
+ });
24
+
25
+ const props = withDefaults(
26
+ defineProps<{
27
+ config: ColumnConfig;
28
+ }>(),
29
+ {
30
+ config: () => ({}),
31
+ },
32
+ );
33
+
34
+ const componentProps = (row: any) => {
35
+ if (typeof props.config.props === 'function') {
36
+ return props.config.props(row) || {};
37
+ }
38
+ return props.config.props || {};
39
+ };
40
+ </script>
@@ -18,13 +18,17 @@
18
18
  </TMagicTableColumn>
19
19
  </template>
20
20
 
21
- <script lang="ts" setup name="MTableExpandColumn">
21
+ <script lang="ts" setup>
22
22
  import { TMagicTableColumn } from '@tmagic/design';
23
23
  import { MForm } from '@tmagic/form';
24
24
 
25
25
  import { ColumnConfig } from './schema';
26
26
  import MTable from './Table.vue';
27
27
 
28
+ defineOptions({
29
+ name: 'MTableExpandColumn',
30
+ });
31
+
28
32
  const props = withDefaults(
29
33
  defineProps<{
30
34
  config: ColumnConfig;
@@ -21,13 +21,17 @@
21
21
  </TMagicTableColumn>
22
22
  </template>
23
23
 
24
- <script lang="ts" setup name="MTablePopoverColumn">
24
+ <script lang="ts" setup>
25
25
  import { TMagicButton, TMagicPopover, TMagicTableColumn } from '@tmagic/design';
26
26
 
27
27
  import { ColumnConfig } from './schema';
28
28
  import MTable from './Table.vue';
29
29
  import { formatter } from './utils';
30
30
 
31
+ defineOptions({
32
+ name: 'MTablePopoverColumn',
33
+ });
34
+
31
35
  withDefaults(
32
36
  defineProps<{
33
37
  config: ColumnConfig;
package/src/Table.vue CHANGED
@@ -25,11 +25,15 @@
25
25
  <ExpandColumn :config="item" :key="columnIndex"></ExpandColumn>
26
26
  </template>
27
27
 
28
+ <template v-else-if="item.type === 'component'">
29
+ <ComponentColumn :config="item" :key="columnIndex"></ComponentColumn>
30
+ </template>
31
+
28
32
  <template v-else-if="item.selection">
29
33
  <component
30
34
  width="40"
31
35
  type="selection"
32
- :is="tableColumnComponent.component"
36
+ :is="tableColumnComponent?.component || 'el-table-column'"
33
37
  :key="columnIndex"
34
38
  :selectable="item.selectable"
35
39
  ></component>
@@ -57,17 +61,22 @@
57
61
  </TMagicTable>
58
62
  </template>
59
63
 
60
- <script lang="ts" setup name="MTable">
64
+ <script lang="ts" setup>
61
65
  import { computed, ref } from 'vue';
62
66
  import { cloneDeep } from 'lodash-es';
63
67
 
64
68
  import { getConfig, TMagicTable } from '@tmagic/design';
65
69
 
66
70
  import ActionsColumn from './ActionsColumn.vue';
71
+ import ComponentColumn from './ComponentColumn.vue';
67
72
  import ExpandColumn from './ExpandColumn.vue';
68
73
  import PopoverColumn from './PopoverColumn.vue';
69
74
  import TextColumn from './TextColumn.vue';
70
75
 
76
+ defineOptions({
77
+ name: 'MTable',
78
+ });
79
+
71
80
  const props = withDefaults(
72
81
  defineProps<{
73
82
  data: any[];
@@ -110,7 +119,7 @@ const tMagicTable = ref<InstanceType<typeof TMagicTable>>();
110
119
 
111
120
  const editState = ref([]);
112
121
 
113
- const tableColumnComponent = getConfig('components').tableColumn;
122
+ const tableColumnComponent = getConfig('components')?.tableColumn;
114
123
  const selectionColumn = computed(() => {
115
124
  const column = props.columns.filter((item) => item.selection);
116
125
  return column.length ? column[0] : null;
@@ -43,7 +43,7 @@
43
43
  <template #content>
44
44
  <div>{{ formatter(config, scope.row) }}</div>
45
45
  </template>
46
- <TMagicButton text type="primary">扩展配置</TMagicButton>
46
+ <TMagicButton text type="primary">{{ config.buttonText || '扩展配置' }}</TMagicButton>
47
47
  </el-tooltip>
48
48
 
49
49
  <TMagicTag
@@ -57,12 +57,16 @@
57
57
  </TMagicTableColumn>
58
58
  </template>
59
59
 
60
- <script lang="ts" setup name="MTableColumn">
60
+ <script lang="ts" setup>
61
61
  import { TMagicButton, TMagicForm, TMagicTableColumn, TMagicTag } from '@tmagic/design';
62
62
 
63
63
  import { ColumnConfig } from './schema';
64
64
  import { formatter } from './utils';
65
65
 
66
+ defineOptions({
67
+ name: 'MTableColumn',
68
+ });
69
+
66
70
  withDefaults(
67
71
  defineProps<{
68
72
  config: ColumnConfig;
package/src/schema.ts CHANGED
@@ -24,6 +24,8 @@ export interface ColumnActionConfig {
24
24
  display?: (row: any) => boolean;
25
25
  text: string | ((row: any) => string);
26
26
  name: string;
27
+ tooltip?: string;
28
+ tooltipPlacement?: string;
27
29
  icon?: any;
28
30
  handler?: (row: any, index: number) => Promise<any> | any;
29
31
  before?: (row: any, index: number) => void;
@@ -41,7 +43,7 @@ export type ColumnConfig = {
41
43
  fixed?: 'left' | 'right' | boolean;
42
44
  width?: number | string;
43
45
  actions?: ColumnActionConfig[];
44
- type?: 'popover' | 'expand' | string | ((value: any, row: any) => string);
46
+ type?: 'popover' | 'expand' | 'component' | string | ((value: any, row: any) => string);
45
47
  text?: string;
46
48
  prop?: string;
47
49
  showHeader?: boolean;
@@ -58,8 +60,10 @@ export type ColumnConfig = {
58
60
  handler?: (row: any) => void;
59
61
  /** 当type为expand时有效,展开为html */
60
62
  expandContent?: (row: any, prop?: string) => string;
61
- /** 当type为expand时有效,展开为vue组件 */
63
+ /** 当type为expand时,展开为vue组件;当type为component时显示的组件 */
62
64
  component?: any;
63
65
  /** 当type为expand时有效,展开的vue组件props */
64
66
  props?: any;
67
+ /** 当type为tip时有效,显示文案 */
68
+ buttonText?: string;
65
69
  };
@@ -26,7 +26,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
26
26
  config: ColumnConfig;
27
27
  rowkeyName: string;
28
28
  editState: any;
29
- }>;
29
+ }, {}>;
30
30
  export default _default;
31
31
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
32
32
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -38,7 +38,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
38
38
  };
39
39
  };
40
40
  type __VLS_WithDefaults<P, D> = {
41
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
41
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
42
42
  default: D[K];
43
- } : P[K];
43
+ }> : P[K];
44
44
  };
45
+ type __VLS_Prettify<T> = {
46
+ [K in keyof T]: T[K];
47
+ } & {};
@@ -0,0 +1,30 @@
1
+ import { ColumnConfig } from './schema';
2
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
+ config: ColumnConfig;
4
+ }>, {
5
+ config: () => {};
6
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
7
+ config: ColumnConfig;
8
+ }>, {
9
+ config: () => {};
10
+ }>>>, {
11
+ config: ColumnConfig;
12
+ }, {}>;
13
+ export default _default;
14
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
15
+ type __VLS_TypePropsToRuntimeProps<T> = {
16
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
17
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
18
+ } : {
19
+ type: import('vue').PropType<T[K]>;
20
+ required: true;
21
+ };
22
+ };
23
+ type __VLS_WithDefaults<P, D> = {
24
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
25
+ default: D[K];
26
+ }> : P[K];
27
+ };
28
+ type __VLS_Prettify<T> = {
29
+ [K in keyof T]: T[K];
30
+ } & {};
@@ -3,13 +3,13 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
3
3
  config: ColumnConfig;
4
4
  }>, {
5
5
  config: () => {};
6
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
6
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
7
7
  config: ColumnConfig;
8
8
  }>, {
9
9
  config: () => {};
10
10
  }>>>, {
11
11
  config: ColumnConfig;
12
- }>;
12
+ }, {}>;
13
13
  export default _default;
14
14
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
15
15
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -21,7 +21,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
21
21
  };
22
22
  };
23
23
  type __VLS_WithDefaults<P, D> = {
24
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
24
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
25
25
  default: D[K];
26
- } : P[K];
26
+ }> : P[K];
27
27
  };
28
+ type __VLS_Prettify<T> = {
29
+ [K in keyof T]: T[K];
30
+ } & {};
@@ -3,13 +3,13 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
3
3
  config: ColumnConfig;
4
4
  }>, {
5
5
  config: () => {};
6
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
6
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
7
7
  config: ColumnConfig;
8
8
  }>, {
9
9
  config: () => {};
10
10
  }>>>, {
11
11
  config: ColumnConfig;
12
- }>;
12
+ }, {}>;
13
13
  export default _default;
14
14
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
15
15
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -21,7 +21,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
21
21
  };
22
22
  };
23
23
  type __VLS_WithDefaults<P, D> = {
24
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
24
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
25
25
  default: D[K];
26
- } : P[K];
26
+ }> : P[K];
27
27
  };
28
+ type __VLS_Prettify<T> = {
29
+ [K in keyof T]: T[K];
30
+ } & {};
@@ -72,7 +72,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
72
72
  showHeader: boolean;
73
73
  defaultExpandAll: boolean;
74
74
  border: boolean;
75
- }>;
75
+ }, {}>;
76
76
  export default _default;
77
77
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
78
78
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -84,7 +84,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
84
84
  };
85
85
  };
86
86
  type __VLS_WithDefaults<P, D> = {
87
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
87
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
88
88
  default: D[K];
89
- } : P[K];
89
+ }> : P[K];
90
90
  };
91
+ type __VLS_Prettify<T> = {
92
+ [K in keyof T]: T[K];
93
+ } & {};
@@ -5,7 +5,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
5
5
  }>, {
6
6
  config: () => {};
7
7
  editState: () => {};
8
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
8
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
9
9
  config: ColumnConfig;
10
10
  editState?: any;
11
11
  }>, {
@@ -14,7 +14,7 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
14
14
  }>>>, {
15
15
  config: ColumnConfig;
16
16
  editState: any;
17
- }>;
17
+ }, {}>;
18
18
  export default _default;
19
19
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
20
20
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -26,7 +26,10 @@ type __VLS_TypePropsToRuntimeProps<T> = {
26
26
  };
27
27
  };
28
28
  type __VLS_WithDefaults<P, D> = {
29
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? P[K] & {
29
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
30
30
  default: D[K];
31
- } : P[K];
31
+ }> : P[K];
32
32
  };
33
+ type __VLS_Prettify<T> = {
34
+ [K in keyof T]: T[K];
35
+ } & {};
package/types/schema.d.ts CHANGED
@@ -5,6 +5,8 @@ export interface ColumnActionConfig {
5
5
  display?: (row: any) => boolean;
6
6
  text: string | ((row: any) => string);
7
7
  name: string;
8
+ tooltip?: string;
9
+ tooltipPlacement?: string;
8
10
  icon?: any;
9
11
  handler?: (row: any, index: number) => Promise<any> | any;
10
12
  before?: (row: any, index: number) => void;
@@ -23,7 +25,7 @@ export type ColumnConfig = {
23
25
  fixed?: 'left' | 'right' | boolean;
24
26
  width?: number | string;
25
27
  actions?: ColumnActionConfig[];
26
- type?: 'popover' | 'expand' | string | ((value: any, row: any) => string);
28
+ type?: 'popover' | 'expand' | 'component' | string | ((value: any, row: any) => string);
27
29
  text?: string;
28
30
  prop?: string;
29
31
  showHeader?: boolean;
@@ -40,8 +42,10 @@ export type ColumnConfig = {
40
42
  handler?: (row: any) => void;
41
43
  /** 当type为expand时有效,展开为html */
42
44
  expandContent?: (row: any, prop?: string) => string;
43
- /** 当type为expand时有效,展开为vue组件 */
45
+ /** 当type为expand时,展开为vue组件;当type为component时显示的组件 */
44
46
  component?: any;
45
47
  /** 当type为expand时有效,展开的vue组件props */
46
48
  props?: any;
49
+ /** 当type为tip时有效,显示文案 */
50
+ buttonText?: string;
47
51
  };