@gx-design-vue/pro-table 0.2.0-alpha.8 → 0.2.0-alpha.9

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 (133) hide show
  1. package/dist/ProTable.d.ts +14 -492
  2. package/dist/ProTable.js +818 -518
  3. package/dist/components/ScrollBar/Bar.d.ts +81 -0
  4. package/dist/components/ScrollBar/Bar.js +84 -0
  5. package/dist/components/ScrollBar/Thumb.d.ts +52 -0
  6. package/dist/components/ScrollBar/{Thumb/index.js → Thumb.js} +67 -55
  7. package/dist/components/ScrollBar/context.d.ts +3 -4
  8. package/dist/components/ScrollBar/context.js +3 -3
  9. package/dist/components/ScrollBar/util.d.ts +6 -5
  10. package/dist/components/ScrollBar/util.js +1 -12
  11. package/dist/components/SearchForm/CollapseToggle.d.ts +55 -0
  12. package/dist/components/SearchForm/CollapseToggle.js +47 -0
  13. package/dist/components/SearchForm/FormItemContainer.d.ts +75 -0
  14. package/dist/components/SearchForm/FormItemContainer.js +225 -0
  15. package/dist/components/SearchForm/FormItemWrapper.d.ts +82 -0
  16. package/dist/components/SearchForm/FormItemWrapper.js +62 -0
  17. package/dist/components/SearchForm/SearchForm.d.ts +130 -0
  18. package/dist/components/SearchForm/SearchForm.js +319 -0
  19. package/dist/components/SearchForm/index.d.ts +2 -0
  20. package/dist/components/SearchForm/index.js +2 -0
  21. package/dist/components/Toolbar/FullscreenIcon.d.ts +26 -0
  22. package/dist/components/Toolbar/FullscreenIcon.js +22 -0
  23. package/dist/components/Toolbar/ListToolBar.d.ts +111 -0
  24. package/dist/components/Toolbar/ListToolBar.js +101 -0
  25. package/dist/components/Toolbar/index.d.ts +103 -0
  26. package/dist/components/Toolbar/index.js +101 -0
  27. package/dist/components/Toolbar/style.d.ts +8 -0
  28. package/dist/components/{ListToolBar → Toolbar}/style.js +32 -27
  29. package/dist/context/TableContext.d.ts +15 -27
  30. package/dist/context/TableContext.js +3 -3
  31. package/dist/hooks/index.d.ts +16 -0
  32. package/dist/hooks/index.js +16 -0
  33. package/dist/hooks/useBreakpoints.d.ts +13 -0
  34. package/dist/hooks/useBreakpoints.js +57 -0
  35. package/dist/hooks/useCellRender.d.ts +13 -0
  36. package/dist/hooks/useCellRender.js +28 -0
  37. package/dist/hooks/useColumnResize.d.ts +30 -0
  38. package/dist/hooks/useColumnResize.js +110 -0
  39. package/dist/hooks/useColumns.d.ts +35 -24
  40. package/dist/hooks/useColumns.js +89 -56
  41. package/dist/hooks/useFetchData.d.ts +40 -65
  42. package/dist/hooks/useFetchData.js +157 -172
  43. package/dist/hooks/useFitPage.d.ts +19 -0
  44. package/dist/hooks/useFitPage.js +90 -0
  45. package/dist/hooks/useKeepAliveReload.d.ts +21 -0
  46. package/dist/hooks/useKeepAliveReload.js +24 -0
  47. package/dist/hooks/useLoading.d.ts +18 -7
  48. package/dist/hooks/useLoading.js +26 -8
  49. package/dist/hooks/usePagination.d.ts +10 -7
  50. package/dist/hooks/usePagination.js +37 -26
  51. package/dist/hooks/useRequestOptions.d.ts +18 -0
  52. package/dist/hooks/useRequestOptions.js +39 -0
  53. package/dist/hooks/useRowSelection.d.ts +27 -15
  54. package/dist/hooks/useRowSelection.js +92 -77
  55. package/dist/hooks/useTable.d.ts +19 -77
  56. package/dist/hooks/useTable.js +66 -54
  57. package/dist/hooks/useTableForm.d.ts +15 -83
  58. package/dist/hooks/useTableForm.js +93 -57
  59. package/dist/hooks/useTableScroll.d.ts +33 -31
  60. package/dist/hooks/useTableScroll.js +71 -26
  61. package/dist/hooks/useTableSize.d.ts +17 -7
  62. package/dist/hooks/useTableSize.js +20 -6
  63. package/dist/index.d.ts +10 -7
  64. package/dist/index.js +9 -3
  65. package/dist/interface.d.ts +492 -0
  66. package/dist/pro-table.esm.js +3512 -3965
  67. package/dist/pro-table.js +1 -1
  68. package/dist/style/fit-page.d.ts +4 -2
  69. package/dist/style/fit-page.js +9 -3
  70. package/dist/style/index.d.ts +4 -6
  71. package/dist/style/index.js +24 -74
  72. package/dist/style/list.d.ts +4 -2
  73. package/dist/style/list.js +1 -10
  74. package/dist/style/resizable.d.ts +8 -0
  75. package/dist/style/resizable.js +18 -0
  76. package/dist/style/scroll.d.ts +4 -2
  77. package/dist/style/scroll.js +8 -6
  78. package/dist/style/search.d.ts +8 -0
  79. package/dist/{components/Form/style.js → style/search.js} +22 -8
  80. package/dist/theme/augment.d.ts +8 -0
  81. package/dist/theme/interface/components.d.ts +8 -0
  82. package/dist/utils/dateFormat.d.ts +9 -0
  83. package/dist/utils/dateFormat.js +29 -0
  84. package/dist/utils/formConstants.d.ts +9 -0
  85. package/dist/utils/formConstants.js +29 -0
  86. package/dist/utils/valueFormat.d.ts +9 -0
  87. package/dist/utils/valueFormat.js +27 -0
  88. package/package.json +10 -9
  89. package/dist/components/Form/components/RequestSelect.d.ts +0 -50
  90. package/dist/components/Form/components/RequestSelect.js +0 -56
  91. package/dist/components/Form/hooks/useForm.d.ts +0 -11
  92. package/dist/components/Form/hooks/useForm.js +0 -30
  93. package/dist/components/Form/index.d.ts +0 -32
  94. package/dist/components/Form/index.js +0 -504
  95. package/dist/components/Form/style.d.ts +0 -6
  96. package/dist/components/Form/utils/config.d.ts +0 -9
  97. package/dist/components/Form/utils/config.js +0 -29
  98. package/dist/components/Form/utils/dateFormat.d.ts +0 -22
  99. package/dist/components/Form/utils/dateFormat.js +0 -43
  100. package/dist/components/ListToolBar/index.d.ts +0 -59
  101. package/dist/components/ListToolBar/index.js +0 -123
  102. package/dist/components/ListToolBar/style.d.ts +0 -6
  103. package/dist/components/ScrollBar/Bar/index.d.ts +0 -49
  104. package/dist/components/ScrollBar/Bar/index.js +0 -68
  105. package/dist/components/ScrollBar/Bar/props.d.ts +0 -25
  106. package/dist/components/ScrollBar/Bar/props.js +0 -17
  107. package/dist/components/ScrollBar/Thumb/index.d.ts +0 -40
  108. package/dist/components/ScrollBar/Thumb/props.d.ts +0 -20
  109. package/dist/components/ScrollBar/Thumb/props.js +0 -17
  110. package/dist/components/TableCell/index.d.ts +0 -37
  111. package/dist/components/TableCell/index.js +0 -69
  112. package/dist/components/ToolBar/FullscreenIcon.d.ts +0 -7
  113. package/dist/components/ToolBar/FullscreenIcon.js +0 -11
  114. package/dist/components/ToolBar/index.d.ts +0 -34
  115. package/dist/components/ToolBar/index.js +0 -97
  116. package/dist/hooks/tryOnActivated.d.ts +0 -6
  117. package/dist/hooks/tryOnActivated.js +0 -12
  118. package/dist/hooks/useDebounceFn.d.ts +0 -8
  119. package/dist/hooks/useDebounceFn.js +0 -31
  120. package/dist/hooks/useScrollArea.d.ts +0 -24
  121. package/dist/hooks/useScrollArea.js +0 -102
  122. package/dist/props.d.ts +0 -340
  123. package/dist/props.js +0 -247
  124. package/dist/types/ColumnTypings.d.ts +0 -130
  125. package/dist/types/SlotsTypings.d.ts +0 -63
  126. package/dist/types/SlotsTypings.js +0 -12
  127. package/dist/types/TableTypings.d.ts +0 -359
  128. package/dist/types/index.d.ts +0 -9
  129. package/dist/utils/utils.d.ts +0 -10
  130. package/dist/utils/utils.js +0 -89
  131. /package/dist/{types/ColumnTypings.js → interface.js} +0 -0
  132. /package/dist/{types/TableTypings.js → theme/augment.js} +0 -0
  133. /package/dist/{types/index.js → theme/interface/components.js} +0 -0
@@ -0,0 +1,101 @@
1
+ import { useInjectTableContext } from "../../context/TableContext.js";
2
+ import { FullscreenIcon } from "./FullscreenIcon.js";
3
+ import { ListToolBar } from "./ListToolBar.js";
4
+ import { computed, createVNode, defineComponent, unref } from "vue";
5
+ import { Tooltip } from "antdv-next";
6
+ import { ReloadOutlined } from "@antdv-next/icons";
7
+ //#region src/components/Toolbar/index.tsx
8
+ function isObject(val) {
9
+ return val !== null && typeof val === "object";
10
+ }
11
+ const Toolbar = /* @__PURE__ */ defineComponent({
12
+ name: "ProTableToolbar",
13
+ props: {
14
+ prefixCls: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ options: {
19
+ type: [Object, Boolean],
20
+ default: false
21
+ },
22
+ titleTipText: {
23
+ type: String,
24
+ default: void 0
25
+ },
26
+ actionsPlacement: {
27
+ type: String,
28
+ default: "right"
29
+ },
30
+ actions: {
31
+ type: Array,
32
+ default: () => []
33
+ },
34
+ headerTitle: {
35
+ type: null,
36
+ default: void 0
37
+ },
38
+ listToolAfter: {
39
+ type: null,
40
+ default: void 0
41
+ },
42
+ headerTitleTip: {
43
+ type: null,
44
+ default: void 0
45
+ },
46
+ proClasses: {
47
+ type: Object,
48
+ default: () => ({})
49
+ },
50
+ proStyles: {
51
+ type: Object,
52
+ default: () => ({})
53
+ }
54
+ },
55
+ setup(props) {
56
+ const ctx = useInjectTableContext();
57
+ const settings = computed(() => {
58
+ if (props.options === false) return [];
59
+ const options = isObject(props.options) ? props.options : {};
60
+ const result = [];
61
+ if (options.reload !== false) {
62
+ const reloadAction = () => ctx?.reload?.();
63
+ if (typeof options.reload === "function") {
64
+ const vnode = options.reload(reloadAction);
65
+ if (vnode) result.push(vnode);
66
+ } else result.push(createVNode(Tooltip, {
67
+ "title": "刷新",
68
+ "key": "reload"
69
+ }, { default: () => [createVNode("span", { "onClick": reloadAction }, [createVNode(ReloadOutlined, null, null)])] }));
70
+ }
71
+ if (options.fullScreen !== false) {
72
+ const toggleAction = () => ctx?.toggleFullscreen?.();
73
+ if (typeof options.fullScreen === "function") result.push(createVNode(FullscreenIcon, {
74
+ "key": "fullscreen",
75
+ "isFullscreen": !!ctx?.isFullscreen?.value,
76
+ "onToggle": options.fullScreen
77
+ }, null));
78
+ else result.push(createVNode(FullscreenIcon, {
79
+ "key": "fullscreen",
80
+ "isFullscreen": !!ctx?.isFullscreen?.value,
81
+ "onToggle": toggleAction
82
+ }, null));
83
+ }
84
+ return result;
85
+ });
86
+ return () => createVNode(ListToolBar, {
87
+ "prefixCls": props.prefixCls,
88
+ "actions": props.actions,
89
+ "actionsPlacement": props.actionsPlacement,
90
+ "settings": unref(settings),
91
+ "headerTitle": props.headerTitle,
92
+ "listToolAfter": props.listToolAfter,
93
+ "headerTitleTip": props.headerTitleTip,
94
+ "titleTipText": props.titleTipText,
95
+ "proClasses": props.proClasses,
96
+ "proStyles": props.proStyles
97
+ }, null);
98
+ }
99
+ });
100
+ //#endregion
101
+ export { Toolbar, Toolbar as default };
@@ -0,0 +1,8 @@
1
+ import { ProFullToken } from "@gx-design-vue/pro-provider";
2
+ import { CSSObject } from "@antdv-next/cssinjs";
3
+ import { GenerateStyle } from "antdv-next/dist/theme/internal";
4
+
5
+ //#region src/components/Toolbar/style.d.ts
6
+ declare const genToolbarStyle: GenerateStyle<ProFullToken<'ProTable'>, CSSObject>;
7
+ //#endregion
8
+ export { genToolbarStyle };
@@ -1,33 +1,25 @@
1
- //#region src/components/ListToolBar/style.ts
2
- const genListToolBarStyle = (token) => {
3
- return { [`${token.componentCls}-list-toolbar`]: {
1
+ //#region src/components/Toolbar/style.ts
2
+ const genToolbarStyle = (token) => {
3
+ const prefixCls = token.componentCls;
4
+ return { [prefixCls]: { [`${prefixCls}-list-toolbar`]: {
4
5
  lineHeight: 1,
5
- "&-with-after": { paddingBottom: token.margin },
6
6
  "&-container": {
7
7
  display: "flex",
8
8
  alignItems: "center",
9
9
  justifyContent: "space-between",
10
10
  gap: token.padding,
11
- paddingBottom: token.padding,
12
- "&-mobile": {
13
- flexDirection: "column",
14
- flexWrap: "wrap",
15
- alignItems: "flex-start",
16
- [`${token.componentCls}-left`]: {
17
- flexWrap: "wrap",
18
- maxWidth: "100%"
19
- },
20
- [`${token.componentCls}-right`]: { width: "100%" }
21
- }
11
+ paddingBottom: token.padding
22
12
  },
23
13
  "&-title": {
24
14
  display: "flex",
25
15
  alignItems: "center",
26
16
  justifyContent: "flex-start",
27
- width: "100%",
28
17
  color: token.colorTextHeading,
29
18
  fontWeight: "500",
30
- fontSize: token.fontSizeLG
19
+ fontSize: token.fontSizeLG,
20
+ overflow: "hidden",
21
+ textOverflow: "ellipsis",
22
+ whiteSpace: "nowrap"
31
23
  },
32
24
  "&-left": {
33
25
  display: "flex",
@@ -35,20 +27,19 @@ const genListToolBarStyle = (token) => {
35
27
  alignItems: "center",
36
28
  gap: token.marginXS,
37
29
  justifyContent: "flex-start",
38
- [`${token.antCls}-tabs`]: { width: "100%" },
39
- "&-has-tabs": { overflow: "hidden" }
30
+ flexShrink: 0
40
31
  },
41
32
  "&-right": {
42
33
  flex: 1,
43
34
  display: "flex",
44
35
  flexWrap: "wrap",
45
36
  justifyContent: "flex-end",
46
- gap: token.marginSM,
47
- [`${token.componentCls}-actions`]: {
48
- display: "flex",
49
- alignItems: "center",
50
- gap: token.marginXS
51
- }
37
+ gap: token.marginSM
38
+ },
39
+ "&-actions": {
40
+ display: "flex",
41
+ alignItems: "center",
42
+ gap: token.marginXS
52
43
  },
53
44
  "&-setting-items": {
54
45
  display: "flex",
@@ -67,8 +58,22 @@ const genListToolBarStyle = (token) => {
67
58
  height: "100%"
68
59
  },
69
60
  "&:hover": { color: token.colorPrimary }
61
+ },
62
+ "&-after": { paddingBottom: token.margin },
63
+ [`@media (max-width: ${token.screenLGMax}px)`]: {
64
+ [`${prefixCls}-list-toolbar-container`]: {
65
+ flexDirection: "column",
66
+ flexWrap: "wrap",
67
+ alignItems: "flex-start"
68
+ },
69
+ [`${prefixCls}-list-toolbar-left`]: {
70
+ flexWrap: "wrap",
71
+ maxWidth: "100%",
72
+ overflow: "visible"
73
+ },
74
+ [`${prefixCls}-list-toolbar-right`]: { width: "100%" }
70
75
  }
71
- } };
76
+ } } };
72
77
  };
73
78
  //#endregion
74
- export { genListToolBarStyle };
79
+ export { genToolbarStyle };
@@ -1,32 +1,20 @@
1
- import { ProColumnsType } from "../types/ColumnTypings.js";
2
- import { FormConfig, TableClassNamesType, TableScroll, TableStylesType } from "../types/TableTypings.js";
1
+ import { FormConfig, ProTableSizeType } from "../interface.js";
3
2
  import { ComputedRef, Ref } from "vue";
4
- import { SizeType } from "@gx-design-vue/pro-utils";
5
- import { PaginationProps } from "ant-design-vue/es/pagination";
6
3
 
7
4
  //#region src/context/TableContext.d.ts
8
- interface ProTableContextProps {
9
- columns: ComputedRef<ProColumnsType>;
10
- isMobile: ComputedRef<boolean>;
11
- formConfig: ComputedRef<FormConfig>;
12
- formActions: ComputedRef<FormConfig['actions']>;
13
- formAutoRequest: ComputedRef<boolean>;
14
- cacheColumns: ComputedRef<ProColumnsType>;
15
- tableSize: Ref<SizeType>;
16
- tableScrollState: ComputedRef<TableScroll>;
17
- screenWidth: Ref<number>;
18
- styles: Ref<TableStylesType>;
19
- classNames: Ref<TableClassNamesType>;
20
- hashId: Ref<string>;
21
- prefixCls: string;
22
- tableListToolsHeight: Ref<number>;
23
- action: {
24
- /** @name 刷新 */reload: (info?: any) => void;
25
- toggle: () => Promise<void>;
26
- setTableSize: (size: SizeType) => void;
27
- };
28
- setPagination: (info: Partial<PaginationProps>) => void;
5
+ interface TableContextProps {
6
+ reload: (info?: any) => void;
7
+ setPagination: (info: any) => void;
8
+ tableSize?: ComputedRef<ProTableSizeType>;
9
+ setTableSize?: (size: ProTableSizeType) => void;
10
+ formAutoRequest?: ComputedRef<boolean>;
11
+ formConfig?: ComputedRef<FormConfig | undefined>;
12
+ formActions?: ComputedRef<FormConfig['actions'] | undefined>;
13
+ isMobile?: ComputedRef<boolean>;
14
+ screenWidth?: ComputedRef<number>;
15
+ toggleFullscreen?: () => Promise<void>;
16
+ isFullscreen?: Ref<boolean>;
29
17
  }
30
- declare const provideTableContext: (value: ProTableContextProps) => void, useTableContext: (injectDefaultValue?: ProTableContextProps) => ProTableContextProps;
18
+ declare const useProvideTableContext: (args_0: TableContextProps) => TableContextProps, useInjectTableContext: () => TableContextProps;
31
19
  //#endregion
32
- export { ProTableContextProps, provideTableContext, useTableContext };
20
+ export { TableContextProps, useInjectTableContext, useProvideTableContext };
@@ -1,5 +1,5 @@
1
- import { useContext } from "@gx-design-vue/context";
1
+ import { createInjectionState } from "@vueuse/core";
2
2
  //#region src/context/TableContext.ts
3
- const { provideContext: provideTableContext, useInjectContext: useTableContext } = useContext("pro-table");
3
+ const [useProvideTableContext, useInjectTableContext] = createInjectionState((props) => props);
4
4
  //#endregion
5
- export { provideTableContext, useTableContext };
5
+ export { useInjectTableContext, useProvideTableContext };
@@ -0,0 +1,16 @@
1
+ import { UseProBreakpointsReturn, useProBreakpoints } from "./useBreakpoints.js";
2
+ import { UseCellRenderOptions, useCellRender } from "./useCellRender.js";
3
+ import { UseColumnResizeOptions, UseColumnResizeReturn, useColumnResize } from "./useColumnResize.js";
4
+ import { UseColumnsOptions, UseColumnsReturn, useColumns } from "./useColumns.js";
5
+ import { FetchDataAction, FetchDataConfig, useFetchData } from "./useFetchData.js";
6
+ import { UseFitPageOptions, UseFitPageReturn, useFitPage } from "./useFitPage.js";
7
+ import { UseKeepAliveReloadOptions, UseKeepAliveReloadReturn, useKeepAliveReload } from "./useKeepAliveReload.js";
8
+ import { UseLoadingOptions, UseLoadingReturn, useLoading } from "./useLoading.js";
9
+ import { usePagination } from "./usePagination.js";
10
+ import { UseRequestOptionsParams, UseRequestOptionsReturn, useRequestOptions } from "./useRequestOptions.js";
11
+ import { UseRowSelectionOptions, UseRowSelectionReturn, useRowSelection } from "./useRowSelection.js";
12
+ import { UseTableOptions, UseTableReturn, useTable } from "./useTable.js";
13
+ import { UseTableFormOptions, UseTableFormReturn, useTableForm } from "./useTableForm.js";
14
+ import { NormalizedTableScrollPolicy, UseTableScrollOptions, UseTableScrollReturn, useTableScroll } from "./useTableScroll.js";
15
+ import { UseTableSizeOptions, UseTableSizeReturn, useTableSize } from "./useTableSize.js";
16
+ export { type FetchDataAction, type FetchDataConfig, type NormalizedTableScrollPolicy, type UseCellRenderOptions, type UseColumnResizeOptions, type UseColumnResizeReturn, type UseColumnsOptions, type UseColumnsReturn, type UseFitPageOptions, type UseFitPageReturn, type UseKeepAliveReloadOptions, type UseKeepAliveReloadReturn, type UseLoadingOptions, type UseLoadingReturn, type UseProBreakpointsReturn, type UseRequestOptionsParams, type UseRequestOptionsReturn, type UseRowSelectionOptions, type UseRowSelectionReturn, type UseTableFormOptions, type UseTableFormReturn, type UseTableOptions, type UseTableReturn, type UseTableScrollOptions, type UseTableScrollReturn, type UseTableSizeOptions, type UseTableSizeReturn, useCellRender, useColumnResize, useColumns, useFetchData, useFitPage, useKeepAliveReload, useLoading, usePagination, useProBreakpoints, useRequestOptions, useRowSelection, useTable, useTableForm, useTableScroll, useTableSize };
@@ -0,0 +1,16 @@
1
+ import { useProBreakpoints } from "./useBreakpoints.js";
2
+ import { useRequestOptions } from "./useRequestOptions.js";
3
+ import { useCellRender } from "./useCellRender.js";
4
+ import { useColumns } from "./useColumns.js";
5
+ import { useColumnResize } from "./useColumnResize.js";
6
+ import { useFetchData } from "./useFetchData.js";
7
+ import { useFitPage } from "./useFitPage.js";
8
+ import { useKeepAliveReload } from "./useKeepAliveReload.js";
9
+ import { useLoading } from "./useLoading.js";
10
+ import { usePagination } from "./usePagination.js";
11
+ import { useRowSelection } from "./useRowSelection.js";
12
+ import { useTable } from "./useTable.js";
13
+ import { useTableForm } from "./useTableForm.js";
14
+ import { useTableScroll } from "./useTableScroll.js";
15
+ import { useTableSize } from "./useTableSize.js";
16
+ export { useCellRender, useColumnResize, useColumns, useFetchData, useFitPage, useKeepAliveReload, useLoading, usePagination, useProBreakpoints, useRequestOptions, useRowSelection, useTable, useTableForm, useTableScroll, useTableSize };
@@ -0,0 +1,13 @@
1
+ import { ColConfig } from "../interface.js";
2
+ import { ComputedRef } from "vue";
3
+
4
+ //#region src/hooks/useBreakpoints.d.ts
5
+ interface UseProBreakpointsReturn {
6
+ screens: ComputedRef<Record<string, boolean>>;
7
+ isMobile: ComputedRef<boolean>;
8
+ screenWidth: ComputedRef<number>;
9
+ getRowItemsPerBreakpoint: (span: ColConfig | undefined, breakpoint: Record<number, number> | undefined) => number;
10
+ }
11
+ declare function useProBreakpoints(): UseProBreakpointsReturn;
12
+ //#endregion
13
+ export { UseProBreakpointsReturn, useProBreakpoints };
@@ -0,0 +1,57 @@
1
+ import { DEFAULT_BREAKPOINT_SPANS } from "../utils/formConstants.js";
2
+ import { computed } from "vue";
3
+ import { useBreakpoints, useWindowSize } from "@vueuse/core";
4
+ //#region src/hooks/useBreakpoints.ts
5
+ const ANTD_BREAKPOINTS = {
6
+ xs: 0,
7
+ sm: 576,
8
+ md: 768,
9
+ lg: 992,
10
+ xl: 1200,
11
+ xxl: 1600
12
+ };
13
+ function useProBreakpoints() {
14
+ const breakpoints = useBreakpoints(ANTD_BREAKPOINTS);
15
+ const { width: screenWidth } = useWindowSize();
16
+ const screens = computed(() => ({
17
+ xs: breakpoints.isGreaterOrEqual("xs"),
18
+ sm: breakpoints.isGreaterOrEqual("sm"),
19
+ md: breakpoints.isGreaterOrEqual("md"),
20
+ lg: breakpoints.isGreaterOrEqual("lg"),
21
+ xl: breakpoints.isGreaterOrEqual("xl"),
22
+ xxl: breakpoints.isGreaterOrEqual("xxl")
23
+ }));
24
+ const isMobile = computed(() => !screens.value.xl);
25
+ function getRowItemsPerBreakpoint(span, breakpoint) {
26
+ if (breakpoint && typeof breakpoint === "object" && Object.keys(breakpoint).length > 0) return getBreakpointRowLength(breakpoint, screenWidth.value);
27
+ return getColSpanRowLength(span, screens.value);
28
+ }
29
+ return {
30
+ screens,
31
+ isMobile,
32
+ screenWidth: computed(() => screenWidth.value),
33
+ getRowItemsPerBreakpoint
34
+ };
35
+ }
36
+ function getBreakpointRowLength(config, rootWidth) {
37
+ let span = 4;
38
+ const sortedWidths = Object.keys(config).map(Number).filter((key) => !Number.isNaN(key)).sort((a, b) => b - a);
39
+ for (const width of sortedWidths) if (config[width] && rootWidth >= width) {
40
+ span = config[width];
41
+ break;
42
+ }
43
+ return span;
44
+ }
45
+ function getColSpanRowLength(colSpan, rootScreen) {
46
+ let span = 4;
47
+ for (let i = 0; i < DEFAULT_BREAKPOINT_SPANS.length; i += 1) {
48
+ const breakpoint = DEFAULT_BREAKPOINT_SPANS[i].breakpoint;
49
+ if (rootScreen[breakpoint]) {
50
+ span = colSpan?.[breakpoint] ?? DEFAULT_BREAKPOINT_SPANS[i].span;
51
+ break;
52
+ }
53
+ }
54
+ return span;
55
+ }
56
+ //#endregion
57
+ export { useProBreakpoints };
@@ -0,0 +1,13 @@
1
+ import { ProColumnType } from "../interface.js";
2
+ import { ComputedRef } from "vue";
3
+
4
+ //#region src/hooks/useCellRender.d.ts
5
+ interface UseCellRenderOptions {
6
+ columnEmptyText?: ComputedRef<string | ((record: any) => string) | undefined>;
7
+ prefixCls: ComputedRef<string>;
8
+ }
9
+ declare function useCellRender(options: UseCellRenderOptions): {
10
+ wrapColumnRender: (column: ProColumnType) => ProColumnType;
11
+ };
12
+ //#endregion
13
+ export { UseCellRenderOptions, useCellRender };
@@ -0,0 +1,28 @@
1
+ import { valueFormat } from "../utils/valueFormat.js";
2
+ import { isVNode } from "vue";
3
+ import { handleEmptyField } from "@gx-design-vue/pro-utils";
4
+ //#region src/hooks/useCellRender.ts
5
+ function resolveEmptyText(column, record, tableLevelEmptyText) {
6
+ if (column.columnEmptyText !== void 0) return typeof column.columnEmptyText === "function" ? column.columnEmptyText(record) : column.columnEmptyText;
7
+ if (tableLevelEmptyText !== void 0) return typeof tableLevelEmptyText === "function" ? tableLevelEmptyText(record) : tableLevelEmptyText;
8
+ return "-";
9
+ }
10
+ function useCellRender(options) {
11
+ function wrapColumnRender(column) {
12
+ const userRender = column.render;
13
+ const wrappedRender = (value, record, index) => {
14
+ let cellValue = userRender ? userRender(value, record, index) : value;
15
+ if (!userRender && column.valueType && !isVNode(cellValue)) cellValue = valueFormat(cellValue, column.valueType, { className: options.prefixCls.value });
16
+ const emptyText = resolveEmptyText(column, record, options.columnEmptyText?.value);
17
+ const { value: finalValue } = handleEmptyField(cellValue, emptyText);
18
+ return finalValue;
19
+ };
20
+ return {
21
+ ...column,
22
+ render: wrappedRender
23
+ };
24
+ }
25
+ return { wrapColumnRender };
26
+ }
27
+ //#endregion
28
+ export { useCellRender };
@@ -0,0 +1,30 @@
1
+ import { ProColumnType } from "../interface.js";
2
+ import * as _$vue from "vue";
3
+ import { ComputedRef } from "vue";
4
+
5
+ //#region src/hooks/useColumnResize.d.ts
6
+ interface UseColumnResizeOptions {
7
+ columns: ComputedRef<ProColumnType[]>;
8
+ onResize?: (width: number, column: ProColumnType) => void;
9
+ }
10
+ interface UseColumnResizeReturn {
11
+ resizableColumns: ComputedRef<ProColumnType[]>;
12
+ resizableComponents: ComputedRef<{
13
+ header: {
14
+ cell: ReturnType<typeof createResizableTitle>;
15
+ };
16
+ }>;
17
+ }
18
+ interface ResizeInfo {
19
+ size: {
20
+ width: number;
21
+ };
22
+ }
23
+ interface ResizableHeaderCellProps {
24
+ width?: number;
25
+ onResize?: (event: MouseEvent, info: ResizeInfo) => void;
26
+ }
27
+ declare function createResizableTitle(): _$vue.DefineComponent<ResizableHeaderCellProps, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<ResizableHeaderCellProps> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
28
+ declare function useColumnResize(options: UseColumnResizeOptions): UseColumnResizeReturn;
29
+ //#endregion
30
+ export { ResizeInfo, UseColumnResizeOptions, UseColumnResizeReturn, useColumnResize };
@@ -0,0 +1,110 @@
1
+ import { getColumnKey } from "./useColumns.js";
2
+ import { computed, defineComponent, h, onScopeDispose, shallowRef } from "vue";
3
+ //#region src/hooks/useColumnResize.ts
4
+ const MIN_COLUMN_WIDTH = 40;
5
+ function createResizableTitle() {
6
+ return defineComponent({
7
+ name: "ResizableTitle",
8
+ inheritAttrs: false,
9
+ props: {
10
+ width: {
11
+ type: Number,
12
+ default: void 0
13
+ },
14
+ onResize: {
15
+ type: Function,
16
+ default: void 0
17
+ }
18
+ },
19
+ setup(props, { slots, attrs }) {
20
+ const dragging = shallowRef(false);
21
+ const shouldPreventClick = shallowRef(false);
22
+ const startX = shallowRef(0);
23
+ const startWidth = shallowRef(0);
24
+ function onMouseDown(event) {
25
+ event.preventDefault();
26
+ event.stopPropagation();
27
+ dragging.value = true;
28
+ shouldPreventClick.value = false;
29
+ startX.value = event.clientX;
30
+ startWidth.value = props.width || event.currentTarget?.parentElement?.offsetWidth || 0;
31
+ function onMouseMove(moveEvent) {
32
+ if (!dragging.value) return;
33
+ shouldPreventClick.value = true;
34
+ const nextWidth = Math.max(startWidth.value + moveEvent.clientX - startX.value, MIN_COLUMN_WIDTH);
35
+ props.onResize?.(moveEvent, { size: { width: nextWidth } });
36
+ }
37
+ function onMouseUp() {
38
+ dragging.value = false;
39
+ document.removeEventListener("mousemove", onMouseMove);
40
+ document.removeEventListener("mouseup", onMouseUp);
41
+ setTimeout(() => {
42
+ shouldPreventClick.value = false;
43
+ }, 0);
44
+ }
45
+ document.addEventListener("mousemove", onMouseMove);
46
+ document.addEventListener("mouseup", onMouseUp);
47
+ }
48
+ function onClickCapture(event) {
49
+ if (shouldPreventClick.value) {
50
+ event.stopPropagation();
51
+ event.preventDefault();
52
+ shouldPreventClick.value = false;
53
+ }
54
+ }
55
+ return () => {
56
+ if (props.width == null) return h("th", attrs, slots.default?.());
57
+ return h("th", {
58
+ ...attrs,
59
+ class: ["resizable-title", attrs.class],
60
+ style: {
61
+ ...attrs.style,
62
+ width: `${props.width}px`
63
+ },
64
+ onClickCapture
65
+ }, [slots.default?.(), h("span", {
66
+ class: "resizable-handle",
67
+ onMousedown: onMouseDown
68
+ })]);
69
+ };
70
+ }
71
+ });
72
+ }
73
+ function useColumnResize(options) {
74
+ const columnWidthOverrides = shallowRef(/* @__PURE__ */ new Map());
75
+ function handleColumnResize(columnKey, info) {
76
+ const nextMap = new Map(columnWidthOverrides.value);
77
+ nextMap.set(columnKey, info.size.width);
78
+ columnWidthOverrides.value = nextMap;
79
+ }
80
+ const ResizableTitle = createResizableTitle();
81
+ const resizableColumns = computed(() => {
82
+ const source = options.columns.value;
83
+ const overrides = columnWidthOverrides.value;
84
+ return source.map((column) => {
85
+ const columnKey = getColumnKey(column);
86
+ const overriddenWidth = overrides.get(columnKey);
87
+ return {
88
+ ...column,
89
+ ...overriddenWidth != null ? { width: overriddenWidth } : {},
90
+ onHeaderCell: (col) => ({
91
+ width: col.width,
92
+ onResize: (_event, info) => {
93
+ handleColumnResize(getColumnKey(col), info);
94
+ options.onResize?.(info.size.width, col);
95
+ }
96
+ })
97
+ };
98
+ });
99
+ });
100
+ const resizableComponents = computed(() => ({ header: { cell: ResizableTitle } }));
101
+ onScopeDispose(() => {
102
+ columnWidthOverrides.value = /* @__PURE__ */ new Map();
103
+ });
104
+ return {
105
+ resizableColumns,
106
+ resizableComponents
107
+ };
108
+ }
109
+ //#endregion
110
+ export { useColumnResize };
@@ -1,28 +1,39 @@
1
- import { ProColumnType, ProColumnsType } from "../types/ColumnTypings.js";
2
- import { ProTableProps } from "../types/TableTypings.js";
3
- import { ComputedRef, Ref } from "vue";
1
+ import { ProColumnType, ProTableIndexColumn } from "../interface.js";
2
+ import { ComputedRef } from "vue";
3
+ import { AlignType, RecordType } from "@gx-design-vue/pro-utils";
4
4
 
5
5
  //#region src/hooks/useColumns.d.ts
6
- interface UseColumnsType {
7
- scroll: ComputedRef<ProTableProps['scroll']>;
8
- breakpoint: ComputedRef<boolean | undefined>;
9
- columns: ComputedRef<ProColumnsType>;
10
- draggable: Ref<ProTableProps['draggable']>;
11
- neverScroll: Ref<ProTableProps['neverScroll']>;
12
- autoScroll: Ref<ProTableProps['autoScroll']>;
6
+ interface UseColumnsOptions<T = RecordType> {
7
+ columns: ComputedRef<ProColumnType<T>[]>;
8
+ align: ComputedRef<AlignType>;
9
+ indexColumn?: ComputedRef<boolean | ProTableIndexColumn | undefined>;
10
+ shouldFixActionColumn?: ComputedRef<boolean>;
11
+ wrapColumnRender?: (column: ProColumnType<T>) => ProColumnType<T>;
13
12
  }
14
- declare function useColumns({
15
- scroll,
16
- columns,
17
- breakpoint,
18
- draggable,
19
- autoScroll,
20
- neverScroll
21
- }: UseColumnsType): {
22
- breakpoint: ComputedRef<boolean>;
23
- proColumns: ComputedRef<ProColumnsType>;
24
- setColumns: (columnList: ProColumnsType) => void;
25
- resizeColumnWidth: (width: number, col: ProColumnType) => void;
26
- };
13
+ interface UseColumnsReturn<T = RecordType> {
14
+ tableColumns: ComputedRef<ProColumnType<T>[]>;
15
+ cacheColumns: ComputedRef<ProColumnType<T>[]>;
16
+ setColumns: (columns: ProColumnType<any>[]) => void;
17
+ }
18
+ /** 获取列唯一标识,优先 key,回退 dataIndex */
19
+ declare function getColumnKey(col: ProColumnType<any>): string | number;
20
+ /** 规范化单列:补齐 key/dataIndex/align/order,递归处理 children */
21
+ declare function normalizeColumn<T>(col: ProColumnType<T>, index: number, defaultAlign: AlignType): ProColumnType<T>;
22
+ /** 批量规范化列配置 */
23
+ declare function normalizeColumns<T>(columns: ProColumnType<T>[], defaultAlign: AlignType): ProColumnType<T>[];
24
+ declare function applyIndexColumn<T>(columns: ProColumnType<T>[], indexColumn: boolean | ProTableIndexColumn | undefined, defaultAlign: AlignType): ProColumnType<T>[];
25
+ declare function applyActionColumnFixed<T>(columns: ProColumnType<T>[], shouldFixActionColumn: boolean): ProColumnType<T>[];
26
+ /** 过滤掉 show=false 的列 */
27
+ declare function filterVisible<T>(columns: ProColumnType<T>[]): ProColumnType<T>[];
28
+ /** 按 order 字段升序排列 */
29
+ declare function sortByOrder<T>(columns: ProColumnType<T>[]): ProColumnType<T>[];
30
+ /**
31
+ * 列配置管理。
32
+ * 纯函数 + computed 实现,无 watcher/ref 链。
33
+ * - tableColumns: 仅可见列,按 order 排序
34
+ * - cacheColumns: 全量规范化列(含隐藏列)
35
+ * - setColumns: 外部覆写列(用于 sortOrder 同步等),props 变化时自动重置
36
+ */
37
+ declare function useColumns<T = RecordType>(options: UseColumnsOptions<T>): UseColumnsReturn<T>;
27
38
  //#endregion
28
- export { useColumns };
39
+ export { UseColumnsOptions, UseColumnsReturn, applyActionColumnFixed, applyIndexColumn, filterVisible, getColumnKey, normalizeColumn, normalizeColumns, sortByOrder, useColumns };