@nokecy/qc-ui 1.1.39 → 1.1.41

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 (121) hide show
  1. package/dist/cjs/adapters/abpPagedApiAdapter.d.ts +8 -0
  2. package/dist/cjs/adapters/abpPagedApiAdapter.js +35 -0
  3. package/dist/cjs/adapters/index.d.ts +6 -0
  4. package/dist/cjs/adapters/index.js +12 -0
  5. package/dist/cjs/adapters/pagedApiAdapter.d.ts +25 -0
  6. package/dist/cjs/adapters/pagedApiAdapter.js +5 -0
  7. package/dist/cjs/ag-grid-plus/ag-gridPlus.js +51 -205
  8. package/dist/cjs/ag-grid-plus/context/gridContext.d.ts +3 -0
  9. package/dist/cjs/ag-grid-plus/context/queryFormContext.d.ts +20 -0
  10. package/dist/cjs/ag-grid-plus/context/queryFormContext.js +25 -0
  11. package/dist/cjs/ag-grid-plus/errors/ErrorBoundary.d.ts +1 -1
  12. package/dist/cjs/ag-grid-plus/hooks/index.d.ts +1 -3
  13. package/dist/cjs/ag-grid-plus/hooks/index.js +7 -39
  14. package/dist/cjs/ag-grid-plus/hooks/useRowId.d.ts +13 -0
  15. package/dist/cjs/ag-grid-plus/hooks/useRowId.js +57 -0
  16. package/dist/cjs/ag-grid-plus/interface.d.ts +9 -0
  17. package/dist/cjs/ag-grid-plus/setting/QuerySchemeManager.js +6 -6
  18. package/dist/cjs/ag-grid-plus/setting/columnGroupUtils.js +2 -3
  19. package/dist/cjs/ag-grid-plus/types.d.ts +9 -0
  20. package/dist/cjs/ag-grid-plus/utils/aggregation.d.ts +17 -0
  21. package/dist/cjs/ag-grid-plus/utils/aggregation.js +101 -0
  22. package/dist/cjs/ag-grid-plus/utils/columnProcessors.js +2 -2
  23. package/dist/cjs/ag-grid-plus/utils/entityExtensionColumns.d.ts +12 -3
  24. package/dist/cjs/ag-grid-plus/utils/entityExtensionColumns.js +20 -5
  25. package/dist/cjs/ag-grid-plus/utils/queryFormDerivation.d.ts +19 -0
  26. package/dist/cjs/ag-grid-plus/utils/queryFormDerivation.js +49 -0
  27. package/dist/cjs/ag-grid-plus/utils/requestParams.d.ts +15 -0
  28. package/dist/cjs/ag-grid-plus/utils/requestParams.js +31 -0
  29. package/dist/cjs/ag-grid-plus/utils/rowSelection.d.ts +9 -0
  30. package/dist/cjs/ag-grid-plus/utils/rowSelection.js +24 -0
  31. package/dist/cjs/ag-grid-plus/utils.js +2 -2
  32. package/dist/cjs/array-table/arrayBase.js +2 -0
  33. package/dist/cjs/array-table/utils.d.ts +15 -1
  34. package/dist/cjs/array-table/utils.js +48 -20
  35. package/dist/cjs/components/RegexEditor/hooks/useRegexValidation.js +2 -3
  36. package/dist/cjs/components/RegexEditor/hooks/useTemplateManager.js +1 -0
  37. package/dist/cjs/components/RegexEditor/validation/types.d.ts +1 -3
  38. package/dist/cjs/components/RegexEditor/visualizer/astToRailroad.d.ts +0 -2
  39. package/dist/cjs/dashboard/dashboard/index.js +8 -11
  40. package/dist/cjs/dashboard/dashboard/utils.js +3 -6
  41. package/dist/cjs/dashboard/widget/index.js +3 -3
  42. package/dist/cjs/dashboard/widget/selector/index.js +5 -7
  43. package/dist/cjs/dashboard/widget/utils.js +3 -4
  44. package/dist/cjs/dialogSelect/index.d.ts +3 -0
  45. package/dist/cjs/dialogSelect/index.js +16 -13
  46. package/dist/cjs/generatedListPage/GeneratedListPage.js +20 -19
  47. package/dist/cjs/generatedListPage/_utils/toAbpPagedRequest.d.ts +15 -0
  48. package/dist/cjs/generatedListPage/_utils/toAbpPagedRequest.js +26 -0
  49. package/dist/cjs/generatedListPage/types.d.ts +3 -0
  50. package/dist/cjs/index.d.ts +1 -0
  51. package/dist/cjs/index.js +57 -0
  52. package/dist/cjs/standardFormDialog/types.d.ts +7 -0
  53. package/dist/cjs/standardFormDialog/useStandardFormSchema.d.ts +1 -1
  54. package/dist/cjs/standardFormDialog/withStandardForm.js +5 -4
  55. package/dist/esm/adapters/abpPagedApiAdapter.d.ts +8 -0
  56. package/dist/esm/adapters/abpPagedApiAdapter.js +29 -0
  57. package/dist/esm/adapters/index.d.ts +6 -0
  58. package/dist/esm/adapters/index.js +6 -0
  59. package/dist/esm/adapters/pagedApiAdapter.d.ts +25 -0
  60. package/dist/esm/adapters/pagedApiAdapter.js +1 -0
  61. package/dist/esm/ag-grid-plus/ag-gridPlus.js +49 -203
  62. package/dist/esm/ag-grid-plus/context/gridContext.d.ts +3 -0
  63. package/dist/esm/ag-grid-plus/context/queryFormContext.d.ts +20 -0
  64. package/dist/esm/ag-grid-plus/context/queryFormContext.js +19 -0
  65. package/dist/esm/ag-grid-plus/hooks/index.d.ts +1 -3
  66. package/dist/esm/ag-grid-plus/hooks/index.js +2 -6
  67. package/dist/esm/ag-grid-plus/hooks/useRowId.d.ts +13 -0
  68. package/dist/esm/ag-grid-plus/hooks/useRowId.js +52 -0
  69. package/dist/esm/ag-grid-plus/interface.d.ts +9 -0
  70. package/dist/esm/ag-grid-plus/setting/QuerySchemeManager.js +6 -6
  71. package/dist/esm/ag-grid-plus/setting/columnGroupUtils.js +7 -6
  72. package/dist/esm/ag-grid-plus/types.d.ts +9 -0
  73. package/dist/esm/ag-grid-plus/utils/aggregation.d.ts +17 -0
  74. package/dist/esm/ag-grid-plus/utils/aggregation.js +93 -0
  75. package/dist/esm/ag-grid-plus/utils/columnProcessors.js +2 -2
  76. package/dist/esm/ag-grid-plus/utils/entityExtensionColumns.d.ts +12 -3
  77. package/dist/esm/ag-grid-plus/utils/entityExtensionColumns.js +20 -5
  78. package/dist/esm/ag-grid-plus/utils/queryFormDerivation.d.ts +19 -0
  79. package/dist/esm/ag-grid-plus/utils/queryFormDerivation.js +42 -0
  80. package/dist/esm/ag-grid-plus/utils/requestParams.d.ts +15 -0
  81. package/dist/esm/ag-grid-plus/utils/requestParams.js +24 -0
  82. package/dist/esm/ag-grid-plus/utils/rowSelection.d.ts +9 -0
  83. package/dist/esm/ag-grid-plus/utils/rowSelection.js +18 -0
  84. package/dist/esm/ag-grid-plus/utils.js +2 -2
  85. package/dist/esm/array-table/arrayBase.js +2 -0
  86. package/dist/esm/array-table/utils.d.ts +15 -1
  87. package/dist/esm/array-table/utils.js +48 -20
  88. package/dist/esm/components/RegexEditor/hooks/useRegexValidation.js +2 -2
  89. package/dist/esm/components/RegexEditor/hooks/useTemplateManager.js +1 -0
  90. package/dist/esm/components/RegexEditor/validation/types.d.ts +0 -1
  91. package/dist/esm/components/RegexEditor/visualizer/astToRailroad.d.ts +0 -1
  92. package/dist/esm/dashboard/dashboard/index.js +8 -11
  93. package/dist/esm/dashboard/dashboard/utils.js +3 -2
  94. package/dist/esm/dashboard/widget/index.js +3 -3
  95. package/dist/esm/dashboard/widget/selector/index.js +5 -7
  96. package/dist/esm/dashboard/widget/utils.js +3 -3
  97. package/dist/esm/dialogSelect/index.d.ts +3 -0
  98. package/dist/esm/dialogSelect/index.js +16 -13
  99. package/dist/esm/generatedListPage/GeneratedListPage.js +20 -19
  100. package/dist/esm/generatedListPage/_utils/toAbpPagedRequest.d.ts +15 -0
  101. package/dist/esm/generatedListPage/_utils/toAbpPagedRequest.js +20 -0
  102. package/dist/esm/generatedListPage/types.d.ts +3 -0
  103. package/dist/esm/index.d.ts +1 -0
  104. package/dist/esm/index.js +3 -0
  105. package/dist/esm/standardFormDialog/types.d.ts +7 -0
  106. package/dist/esm/standardFormDialog/withStandardForm.js +5 -4
  107. package/dist/umd/qc-ui.min.css +1 -1
  108. package/dist/umd/qc-ui.min.js +1 -1
  109. package/package.json +52 -13
  110. package/dist/cjs/ag-grid-plus/hooks/useAgGridCalculation.d.ts +0 -88
  111. package/dist/cjs/ag-grid-plus/hooks/useAgGridCalculation.js +0 -224
  112. package/dist/cjs/ag-grid-plus/hooks/useAgGridData.d.ts +0 -91
  113. package/dist/cjs/ag-grid-plus/hooks/useAgGridData.js +0 -230
  114. package/dist/cjs/ag-grid-plus/hooks/useGridState.d.ts +0 -153
  115. package/dist/cjs/ag-grid-plus/hooks/useGridState.js +0 -258
  116. package/dist/esm/ag-grid-plus/hooks/useAgGridCalculation.d.ts +0 -88
  117. package/dist/esm/ag-grid-plus/hooks/useAgGridCalculation.js +0 -217
  118. package/dist/esm/ag-grid-plus/hooks/useAgGridData.d.ts +0 -91
  119. package/dist/esm/ag-grid-plus/hooks/useAgGridData.js +0 -225
  120. package/dist/esm/ag-grid-plus/hooks/useGridState.d.ts +0 -153
  121. package/dist/esm/ag-grid-plus/hooks/useGridState.js +0 -258
@@ -1,153 +0,0 @@
1
- /**
2
- * AG-Grid Plus 状态管理 Hook
3
- *
4
- * 使用 useReducer 统一管理组件的所有状态,
5
- * 替代多个 useState 调用,提高性能和可维护性
6
- */
7
- import { Dispatch } from 'react';
8
- import { ColumnState } from 'ag-grid-community';
9
- import type { ExtendedColumnState, ColumnCellConfigMap, QueryFilterState, PaginationState, RowDataArray } from '../types';
10
- /**
11
- * Grid 状态接口
12
- */
13
- export interface GridState {
14
- /** Grid 是否已就绪 */
15
- ready: boolean;
16
- /** 加载状态 */
17
- loading: boolean;
18
- /** 列状态配置 */
19
- columnState?: ExtendedColumnState[];
20
- /** 列单元格样式映射 */
21
- columnCellClass: ColumnCellConfigMap;
22
- /** 行数据 */
23
- rowData: RowDataArray;
24
- /** 选中的行 */
25
- selectRow: any;
26
- /** 查询过滤器 */
27
- queryFilter: QueryFilterState;
28
- /** 排序列 */
29
- sortColumn?: ColumnState;
30
- /** 分页配置 */
31
- pagination: PaginationState;
32
- /** 查询表单项顺序 */
33
- queryItemsOrder: string[];
34
- }
35
- /**
36
- * Action 类型枚举
37
- */
38
- export declare enum GridActionType {
39
- SET_READY = "SET_READY",
40
- SET_LOADING = "SET_LOADING",
41
- SET_COLUMN_STATE = "SET_COLUMN_STATE",
42
- SET_COLUMN_CELL_CLASS = "SET_COLUMN_CELL_CLASS",
43
- SET_ROW_DATA = "SET_ROW_DATA",
44
- SET_SELECT_ROW = "SET_SELECT_ROW",
45
- SET_QUERY_FILTER = "SET_QUERY_FILTER",
46
- SET_SORT_COLUMN = "SET_SORT_COLUMN",
47
- SET_PAGINATION = "SET_PAGINATION",
48
- UPDATE_PAGINATION = "UPDATE_PAGINATION",
49
- SET_QUERY_ITEMS_ORDER = "SET_QUERY_ITEMS_ORDER",
50
- RESET_STATE = "RESET_STATE"
51
- }
52
- /**
53
- * Action 联合类型
54
- */
55
- export type GridAction = {
56
- type: GridActionType.SET_READY;
57
- payload: boolean;
58
- } | {
59
- type: GridActionType.SET_LOADING;
60
- payload: boolean;
61
- } | {
62
- type: GridActionType.SET_COLUMN_STATE;
63
- payload: ExtendedColumnState[] | undefined;
64
- } | {
65
- type: GridActionType.SET_COLUMN_CELL_CLASS;
66
- payload: ColumnCellConfigMap;
67
- } | {
68
- type: GridActionType.SET_ROW_DATA;
69
- payload: RowDataArray;
70
- } | {
71
- type: GridActionType.SET_SELECT_ROW;
72
- payload: any;
73
- } | {
74
- type: GridActionType.SET_QUERY_FILTER;
75
- payload: QueryFilterState;
76
- } | {
77
- type: GridActionType.SET_SORT_COLUMN;
78
- payload: ColumnState | undefined;
79
- } | {
80
- type: GridActionType.SET_PAGINATION;
81
- payload: PaginationState;
82
- } | {
83
- type: GridActionType.UPDATE_PAGINATION;
84
- payload: Partial<PaginationState>;
85
- } | {
86
- type: GridActionType.SET_QUERY_ITEMS_ORDER;
87
- payload: string[];
88
- } | {
89
- type: GridActionType.RESET_STATE;
90
- payload: Partial<GridState>;
91
- };
92
- /**
93
- * Grid 状态 Reducer
94
- */
95
- export declare function gridReducer(state: GridState, action: GridAction): GridState;
96
- /**
97
- * useGridState Hook 配置
98
- */
99
- export interface UseGridStateConfig {
100
- /** 初始加载状态 */
101
- loading?: boolean;
102
- /** 初始分页配置 */
103
- pageSize?: number;
104
- /** 是否隐藏分页 */
105
- hidePagination?: boolean;
106
- /** 数据源(用于计算初始 total) */
107
- dataSource?: any[];
108
- }
109
- /**
110
- * useGridState Hook 返回值
111
- */
112
- export interface UseGridStateReturn {
113
- /** Grid 状态 */
114
- state: GridState;
115
- /** Dispatch 函数 */
116
- dispatch: Dispatch<GridAction>;
117
- /** 便捷的 actions */
118
- actions: {
119
- setReady: (ready: boolean) => void;
120
- setLoading: (loading: boolean) => void;
121
- setColumnState: (columnState: ExtendedColumnState[] | undefined) => void;
122
- setColumnCellClass: (columnCellClass: ColumnCellConfigMap) => void;
123
- setRowData: (rowData: RowDataArray) => void;
124
- setSelectRow: (selectRow: any) => void;
125
- setQueryFilter: (queryFilter: QueryFilterState) => void;
126
- setSortColumn: (sortColumn: ColumnState | undefined) => void;
127
- setPagination: (pagination: PaginationState) => void;
128
- updatePagination: (pagination: Partial<PaginationState>) => void;
129
- setQueryItemsOrder: (order: string[]) => void;
130
- resetState: (state: Partial<GridState>) => void;
131
- };
132
- }
133
- /**
134
- * AG-Grid Plus 状态管理 Hook
135
- *
136
- * @param config 配置对象
137
- * @returns 状态和 actions
138
- *
139
- * @example
140
- * ```tsx
141
- * const { state, actions } = useGridState({
142
- * loading: false,
143
- * pageSize: 200,
144
- * hidePagination: false
145
- * });
146
- *
147
- * // 使用 actions
148
- * actions.setLoading(true);
149
- * actions.setRowData(newData);
150
- * actions.updatePagination({ current: 2 });
151
- * ```
152
- */
153
- export declare function useGridState(config?: UseGridStateConfig): UseGridStateReturn;
@@ -1,258 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- /**
14
- * AG-Grid Plus 状态管理 Hook
15
- *
16
- * 使用 useReducer 统一管理组件的所有状态,
17
- * 替代多个 useState 调用,提高性能和可维护性
18
- */
19
-
20
- import { useReducer } from 'react';
21
-
22
- // ============ State 定义 ============
23
-
24
- /**
25
- * Grid 状态接口
26
- */
27
-
28
- // ============ Action 定义 ============
29
-
30
- /**
31
- * Action 类型枚举
32
- */
33
- export var GridActionType = /*#__PURE__*/function (GridActionType) {
34
- GridActionType["SET_READY"] = "SET_READY";
35
- GridActionType["SET_LOADING"] = "SET_LOADING";
36
- GridActionType["SET_COLUMN_STATE"] = "SET_COLUMN_STATE";
37
- GridActionType["SET_COLUMN_CELL_CLASS"] = "SET_COLUMN_CELL_CLASS";
38
- GridActionType["SET_ROW_DATA"] = "SET_ROW_DATA";
39
- GridActionType["SET_SELECT_ROW"] = "SET_SELECT_ROW";
40
- GridActionType["SET_QUERY_FILTER"] = "SET_QUERY_FILTER";
41
- GridActionType["SET_SORT_COLUMN"] = "SET_SORT_COLUMN";
42
- GridActionType["SET_PAGINATION"] = "SET_PAGINATION";
43
- GridActionType["UPDATE_PAGINATION"] = "UPDATE_PAGINATION";
44
- GridActionType["SET_QUERY_ITEMS_ORDER"] = "SET_QUERY_ITEMS_ORDER";
45
- GridActionType["RESET_STATE"] = "RESET_STATE";
46
- return GridActionType;
47
- }({});
48
-
49
- /**
50
- * Action 联合类型
51
- */
52
-
53
- // ============ Reducer 定义 ============
54
-
55
- /**
56
- * Grid 状态 Reducer
57
- */
58
- export function gridReducer(state, action) {
59
- switch (action.type) {
60
- case GridActionType.SET_READY:
61
- return _objectSpread(_objectSpread({}, state), {}, {
62
- ready: action.payload
63
- });
64
- case GridActionType.SET_LOADING:
65
- return _objectSpread(_objectSpread({}, state), {}, {
66
- loading: action.payload
67
- });
68
- case GridActionType.SET_COLUMN_STATE:
69
- return _objectSpread(_objectSpread({}, state), {}, {
70
- columnState: action.payload
71
- });
72
- case GridActionType.SET_COLUMN_CELL_CLASS:
73
- return _objectSpread(_objectSpread({}, state), {}, {
74
- columnCellClass: action.payload
75
- });
76
- case GridActionType.SET_ROW_DATA:
77
- return _objectSpread(_objectSpread({}, state), {}, {
78
- rowData: action.payload
79
- });
80
- case GridActionType.SET_SELECT_ROW:
81
- return _objectSpread(_objectSpread({}, state), {}, {
82
- selectRow: action.payload
83
- });
84
- case GridActionType.SET_QUERY_FILTER:
85
- return _objectSpread(_objectSpread({}, state), {}, {
86
- queryFilter: action.payload
87
- });
88
- case GridActionType.SET_SORT_COLUMN:
89
- return _objectSpread(_objectSpread({}, state), {}, {
90
- sortColumn: action.payload
91
- });
92
- case GridActionType.SET_PAGINATION:
93
- return _objectSpread(_objectSpread({}, state), {}, {
94
- pagination: action.payload
95
- });
96
- case GridActionType.UPDATE_PAGINATION:
97
- return _objectSpread(_objectSpread({}, state), {}, {
98
- pagination: _objectSpread(_objectSpread({}, state.pagination), action.payload)
99
- });
100
- case GridActionType.SET_QUERY_ITEMS_ORDER:
101
- return _objectSpread(_objectSpread({}, state), {}, {
102
- queryItemsOrder: action.payload
103
- });
104
- case GridActionType.RESET_STATE:
105
- return _objectSpread(_objectSpread({}, state), action.payload);
106
- default:
107
- return state;
108
- }
109
- }
110
-
111
- // ============ Hook 定义 ============
112
-
113
- /**
114
- * useGridState Hook 配置
115
- */
116
-
117
- /**
118
- * useGridState Hook 返回值
119
- */
120
-
121
- /**
122
- * AG-Grid Plus 状态管理 Hook
123
- *
124
- * @param config 配置对象
125
- * @returns 状态和 actions
126
- *
127
- * @example
128
- * ```tsx
129
- * const { state, actions } = useGridState({
130
- * loading: false,
131
- * pageSize: 200,
132
- * hidePagination: false
133
- * });
134
- *
135
- * // 使用 actions
136
- * actions.setLoading(true);
137
- * actions.setRowData(newData);
138
- * actions.updatePagination({ current: 2 });
139
- * ```
140
- */
141
- export function useGridState() {
142
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
143
- var _config$loading = config.loading,
144
- initialLoading = _config$loading === void 0 ? false : _config$loading,
145
- initialPageSize = config.pageSize,
146
- _config$hidePaginatio = config.hidePagination,
147
- hidePagination = _config$hidePaginatio === void 0 ? false : _config$hidePaginatio,
148
- _config$dataSource = config.dataSource,
149
- dataSource = _config$dataSource === void 0 ? [] : _config$dataSource;
150
-
151
- // 计算初始分页配置
152
- var initialPagination = {
153
- pageSize: initialPageSize !== undefined ? initialPageSize : hidePagination ? 10000 : 200,
154
- current: 1,
155
- total: dataSource.length
156
- };
157
-
158
- // 初始状态
159
- var initialState = {
160
- ready: false,
161
- loading: initialLoading,
162
- columnState: undefined,
163
- columnCellClass: {},
164
- rowData: [],
165
- selectRow: {},
166
- queryFilter: {},
167
- sortColumn: undefined,
168
- pagination: initialPagination,
169
- queryItemsOrder: []
170
- };
171
-
172
- // 使用 useReducer
173
- var _useReducer = useReducer(gridReducer, initialState),
174
- _useReducer2 = _slicedToArray(_useReducer, 2),
175
- state = _useReducer2[0],
176
- dispatch = _useReducer2[1];
177
-
178
- // 创建便捷的 actions
179
- var actions = {
180
- setReady: function setReady(ready) {
181
- return dispatch({
182
- type: GridActionType.SET_READY,
183
- payload: ready
184
- });
185
- },
186
- setLoading: function setLoading(loading) {
187
- return dispatch({
188
- type: GridActionType.SET_LOADING,
189
- payload: loading
190
- });
191
- },
192
- setColumnState: function setColumnState(columnState) {
193
- return dispatch({
194
- type: GridActionType.SET_COLUMN_STATE,
195
- payload: columnState
196
- });
197
- },
198
- setColumnCellClass: function setColumnCellClass(columnCellClass) {
199
- return dispatch({
200
- type: GridActionType.SET_COLUMN_CELL_CLASS,
201
- payload: columnCellClass
202
- });
203
- },
204
- setRowData: function setRowData(rowData) {
205
- return dispatch({
206
- type: GridActionType.SET_ROW_DATA,
207
- payload: rowData
208
- });
209
- },
210
- setSelectRow: function setSelectRow(selectRow) {
211
- return dispatch({
212
- type: GridActionType.SET_SELECT_ROW,
213
- payload: selectRow
214
- });
215
- },
216
- setQueryFilter: function setQueryFilter(queryFilter) {
217
- return dispatch({
218
- type: GridActionType.SET_QUERY_FILTER,
219
- payload: queryFilter
220
- });
221
- },
222
- setSortColumn: function setSortColumn(sortColumn) {
223
- return dispatch({
224
- type: GridActionType.SET_SORT_COLUMN,
225
- payload: sortColumn
226
- });
227
- },
228
- setPagination: function setPagination(pagination) {
229
- return dispatch({
230
- type: GridActionType.SET_PAGINATION,
231
- payload: pagination
232
- });
233
- },
234
- updatePagination: function updatePagination(pagination) {
235
- return dispatch({
236
- type: GridActionType.UPDATE_PAGINATION,
237
- payload: pagination
238
- });
239
- },
240
- setQueryItemsOrder: function setQueryItemsOrder(order) {
241
- return dispatch({
242
- type: GridActionType.SET_QUERY_ITEMS_ORDER,
243
- payload: order
244
- });
245
- },
246
- resetState: function resetState(newState) {
247
- return dispatch({
248
- type: GridActionType.RESET_STATE,
249
- payload: newState
250
- });
251
- }
252
- };
253
- return {
254
- state: state,
255
- dispatch: dispatch,
256
- actions: actions
257
- };
258
- }