@lemon-fe/kits 1.0.0-46 → 1.0.0-47

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.
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { Store } from '../utils';
3
+ declare const GridStoreContext: import("react").Context<Store<any>>;
4
+ export default GridStoreContext;
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ import { Store } from "../utils";
3
+ var GridStoreContext = /*#__PURE__*/createContext(new Store({}));
4
+ export default GridStoreContext;
@@ -12,9 +12,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { useContext, useEffect, useRef, useState } from 'react';
14
14
  import shallowEqual from 'shallowequal';
15
- import GridContext from "./GridContext";
15
+ import GridStoreContext from "./context/GridStore";
16
16
  export function useGridStore(getter) {
17
- var store = useContext(GridContext);
17
+ var store = useContext(GridStoreContext);
18
18
  var ref = useRef(getter);
19
19
  ref.current = getter;
20
20
 
@@ -1,19 +1,12 @@
1
1
  import React, { Component } from 'react';
2
- import type { ColDef, ColGroupDef } from '@ag-grid-community/core';
3
- import { GridApi } from '@ag-grid-community/core';
4
- import type { ColType, DataGridProps } from './typings';
2
+ import type { ColDef } from '@ag-grid-community/core';
3
+ import { GridApi, ColumnApi } from '@ag-grid-community/core';
4
+ import type { ColType, DataGridProps, DataGridState } from './typings';
5
5
  import EditorWrapper from './cell-editors/Wrapper';
6
- export default class DataGrid<TData> extends Component<DataGridProps<TData>, {
7
- colDefs: (ColDef<TData> | ColGroupDef<TData>)[];
8
- pagination: boolean;
9
- page: number;
10
- pageSize: number;
11
- total: number;
12
- loading: boolean;
13
- }> {
6
+ export default class DataGrid<TData> extends Component<DataGridProps<TData>, DataGridState<TData>> {
14
7
  api: GridApi<any>;
8
+ columnApi: ColumnApi;
15
9
  private selected;
16
- private columnApi;
17
10
  private store;
18
11
  private dataSource;
19
12
  private validator;
@@ -70,7 +70,7 @@ import { ModuleRegistry, GridApi, ColumnApi } from '@ag-grid-community/core';
70
70
  import { InfiniteRowModelModule } from '@ag-grid-community/infinite-row-model';
71
71
  import { get, set } from 'lodash';
72
72
  import Scheme from 'async-validator';
73
- import GridContext from "./GridContext";
73
+ import GridStoreContext from "./context/GridStore";
74
74
  import { RowGroupingModule } from "./modules/row-grouping";
75
75
  import { ClipboardModule } from "./modules/clipboard";
76
76
  import { MenuModule } from "./modules/menu";
@@ -80,9 +80,9 @@ import { ServerSideRowModelModule } from "./modules/server-side-row-model";
80
80
  import { ClientSideRowModelModule } from "./modules/client-side-row-model";
81
81
  import { Spin, Pagination, Empty } from 'antd';
82
82
  import { prefix, getColField, isColumn, withSyncRender, Store, Selection, columnTypes } from "./utils";
83
- import HeaderRenderer from "./HeaderRenderer";
84
- import CellRenderer from "./CellRenderer";
85
- import Actions from "./Actions";
83
+ import HeaderRenderer from "./renderer/HeaderRenderer";
84
+ import CellRenderer from "./renderer/CellRenderer";
85
+ import Actions from "./renderer/Actions";
86
86
  import DateEditor from "./cell-editors/Date";
87
87
  import TextEditor from "./cell-editors/Text";
88
88
  import NumberEditor from "./cell-editors/Number";
@@ -118,10 +118,10 @@ var DataGrid = /*#__PURE__*/function (_Component) {
118
118
 
119
119
  _defineProperty(_assertThisInitialized(_this), "api", new GridApi());
120
120
 
121
- _defineProperty(_assertThisInitialized(_this), "selected", void 0);
122
-
123
121
  _defineProperty(_assertThisInitialized(_this), "columnApi", new ColumnApi());
124
122
 
123
+ _defineProperty(_assertThisInitialized(_this), "selected", void 0);
124
+
125
125
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
126
126
 
127
127
  _defineProperty(_assertThisInitialized(_this), "dataSource", []);
@@ -277,7 +277,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
277
277
  }, _this.getPagination());
278
278
  _this.store = new Store({
279
279
  errors: new Map(),
280
- context: props.context
280
+ context: props.context,
281
+ grid: _assertThisInitialized(_this)
281
282
  });
282
283
  var _props$rowSelection = props.rowSelection;
283
284
  _props$rowSelection = _props$rowSelection === void 0 ? {} : _props$rowSelection;
@@ -1059,7 +1060,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1059
1060
  total = _this$state2.total,
1060
1061
  loading = _this$state2.loading;
1061
1062
  var mPage = _typeof(pagination) === 'object' ? pagination : {};
1062
- return /*#__PURE__*/React.createElement(GridContext.Provider, {
1063
+ return /*#__PURE__*/React.createElement(GridStoreContext.Provider, {
1063
1064
  value: this.store
1064
1065
  }, /*#__PURE__*/React.createElement("div", {
1065
1066
  className: "ag-theme-lemon ".concat(prefix()),
@@ -19,6 +19,10 @@
19
19
  margin-right: 4px;
20
20
  }
21
21
 
22
+ &-cell-align-center {
23
+ text-align: center;
24
+ }
25
+
22
26
  &-editable-cell {
23
27
  padding-right: 0;
24
28
  padding-left: 0;
@@ -179,8 +183,8 @@
179
183
  }
180
184
 
181
185
  .ag-cell:not(.ag-cell-wrap-text) &-editor {
182
- text-overflow: ellipsis;
183
186
  white-space: nowrap;
187
+ text-overflow: ellipsis;
184
188
  }
185
189
 
186
190
  &-cell-error {
@@ -200,8 +204,8 @@
200
204
  bottom: 0;
201
205
  left: 0;
202
206
  display: flex;
203
- justify-content: center;
204
207
  align-items: center;
208
+ justify-content: center;
205
209
  background-color: rgba(255, 255, 255, 0.6);
206
210
  }
207
211
  }
@@ -257,8 +261,8 @@
257
261
  }
258
262
 
259
263
  .ag-cell-inline-editing {
260
- background-color: transparent;
261
264
  height: calc(var(--ag-row-height) - 1px);
265
+ background-color: transparent;
262
266
  }
263
267
 
264
268
  .ag-ltr
@@ -341,10 +345,10 @@
341
345
  .ag-column-drop-vertical-empty-message {
342
346
  display: flex;
343
347
  align-items: center;
344
- border: dashed 1px;
345
- border-color: var(--ag-border-color);
346
348
  margin: calc(var(--ag-grid-size) * 2);
347
349
  padding: calc(var(--ag-grid-size) * 2);
350
+ border: dashed 1px;
351
+ border-color: var(--ag-border-color);
348
352
  }
349
353
 
350
354
  .ag-column-drop-empty-message {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { RowActionsType } from './typings';
2
+ import type { RowActionsType } from '../typings';
3
3
  interface Props<T> {
4
4
  actions: RowActionsType<T>;
5
5
  data: T;
@@ -14,8 +14,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  import React, { useEffect, useRef, useState } from 'react';
16
16
  import classNames from 'classnames';
17
- import Icons from "../Icons";
18
- import { prefixClassName } from "../utils";
17
+ import Icons from "../../Icons";
18
+ import { prefixClassName } from "../../utils";
19
19
  import { Popover } from 'antd';
20
20
  var prefix = prefixClassName('grid-operator');
21
21
 
@@ -0,0 +1,2 @@
1
+ import type { ICellRendererParams } from '@ag-grid-community/core';
2
+ export default function CellIndexRender<TData>(props: ICellRendererParams<TData>): number | null;
@@ -0,0 +1,46 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
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
+
5
+ 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); }
6
+
7
+ 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; }
8
+
9
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ import { useContext, useEffect, useState } from 'react';
14
+ import GridStoreContext from "../context/GridStore";
15
+ export default function CellIndexRender(props) {
16
+ var node = props.node;
17
+
18
+ var _useState = useState(node.rowIndex),
19
+ _useState2 = _slicedToArray(_useState, 2),
20
+ index = _useState2[0],
21
+ setIndex = _useState2[1];
22
+
23
+ var store = useContext(GridStoreContext);
24
+ useEffect(function () {
25
+ var handler = function handler(evt) {
26
+ setIndex(evt.node.rowIndex);
27
+ };
28
+
29
+ node.addEventListener('rowIndexChanged', handler);
30
+ return function () {
31
+ node.removeEventListener('rowIndexChanged', handler);
32
+ };
33
+ }, []);
34
+
35
+ if (index === null) {
36
+ return null;
37
+ }
38
+
39
+ var _ref = store.getState(),
40
+ grid = _ref.grid;
41
+
42
+ var _grid$state = grid.state,
43
+ page = _grid$state.page,
44
+ pageSize = _grid$state.pageSize;
45
+ return (page - 1) * pageSize + index + 1;
46
+ }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  import type { ICellRendererParams } from '@ag-grid-community/core';
3
- import type { ColType } from './typings';
3
+ import type { ColType } from '../typings';
4
4
  export default function CellRenderer<TData>(props: ICellRendererParams<TData> & Exclude<Pick<ColType<TData>, 'render'>, undefined>): JSX.Element;
@@ -23,9 +23,9 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
23
23
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
24
24
 
25
25
  import React from 'react';
26
- import { useGridStore } from "./hooks";
27
- import { prefix } from "./utils";
28
- import EditorWrapper from "./cell-editors/Wrapper";
26
+ import { useGridStore } from "../hooks";
27
+ import { prefix } from "../utils";
28
+ import EditorWrapper from "../cell-editors/Wrapper";
29
29
  export default function CellRenderer(props) {
30
30
  var _ref, _restProps$valueForma;
31
31
 
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { IHeaderParams } from '@ag-grid-community/core';
3
- import type { ColType } from './typings';
3
+ import type { ColType } from '../typings';
4
4
  export default function HeaderRenderer<TData>(props: IHeaderParams<TData> & Pick<ColType<TData>, 'title'> & {
5
5
  children?: ReactNode;
6
6
  }): JSX.Element;
@@ -14,7 +14,7 @@ import React, { useContext } from 'react';
14
14
  import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons';
15
15
  import classNames from 'classnames';
16
16
  import { ConfigProvider } from 'antd';
17
- import { useGridStore } from "./hooks";
17
+ import { useGridStore } from "../hooks";
18
18
 
19
19
  function Sort(props) {
20
20
  var value = props.value;
@@ -7,6 +7,7 @@ import type { NumberEditorParams } from './cell-editors/Number';
7
7
  import type { DateEditorParams } from './cell-editors/Date';
8
8
  import type { SelectEditorParams } from './cell-editors/Select';
9
9
  import type { RowEditorParams } from './cell-editors/Row';
10
+ import type DataGrid from './index';
10
11
  export type { TextEditorParams } from './cell-editors/Text';
11
12
  export type { NumberEditorParams } from './cell-editors/Number';
12
13
  export type { DateEditorParams } from './cell-editors/Date';
@@ -73,9 +74,18 @@ export declare type SortType = {
73
74
  field: string;
74
75
  order: SortOrder;
75
76
  };
77
+ export declare type DataGridState<TData> = {
78
+ colDefs: (ColDef<TData> | ColGroupDef<TData>)[];
79
+ pagination: boolean;
80
+ page: number;
81
+ pageSize: number;
82
+ total: number;
83
+ loading: boolean;
84
+ };
76
85
  export declare type GridStore = {
77
86
  errors: Map<string, Map<string, string[]>>;
78
87
  context?: any;
88
+ grid: DataGrid<any>;
79
89
  };
80
90
  export interface RowAction<T> {
81
91
  /**
@@ -26,6 +26,7 @@ import { Subject } from '@lemon-fe/utils';
26
26
  import { get as _get, set as _set } from 'lodash';
27
27
  import moment from 'moment';
28
28
  import { prefixClassName } from "../utils";
29
+ import CellIndexRender from "./renderer/CellIndexRenderer";
29
30
  export var prefix = prefixClassName('grid');
30
31
  export function isColumn(col) {
31
32
  return col.children === undefined;
@@ -255,5 +256,12 @@ export var columnTypes = {
255
256
  headerClass: 'ag-right-aligned-header',
256
257
  cellClass: 'ag-right-aligned-cell',
257
258
  width: 120
259
+ },
260
+ index: {
261
+ headerName: '序号',
262
+ cellRenderer: CellIndexRender,
263
+ width: 45,
264
+ suppressMenu: true,
265
+ cellClass: prefix('cell-align-center')
258
266
  }
259
267
  };
package/es/index.d.ts CHANGED
@@ -31,7 +31,8 @@ export { default as Dropdown } from './components/Dropdown';
31
31
  export { default as SelectView } from './components/SelectView';
32
32
  export { default as DataGrid } from './components/DataGrid';
33
33
  export * from './components/DataGrid/typings';
34
- export type { ColDef, ColGroupDef, ColumnState, GridApi, GridOptions, ICellEditorParams, ICellRendererParams, IHeaderParams, RowDataUpdatedEvent, CellValueChangedEvent, NavigateToNextCellParams, TabToNextCellParams, } from '@ag-grid-community/core';
34
+ export type { ColDef, ColGroupDef, ColumnState, GridOptions, GridReadyEvent, ICellEditorParams, ICellRendererParams, IHeaderParams, RowDataUpdatedEvent, CellValueChangedEvent, NavigateToNextCellParams, TabToNextCellParams, } from '@ag-grid-community/core';
35
+ export { GridApi, ColumnApi } from '@ag-grid-community/core';
35
36
  export * from '@ag-grid-community/react';
36
37
  export { default as BasicLayout } from './layouts/BasicLayout';
37
38
  export { default as BlankLayout } from './layouts/BlankLayout';
package/es/index.js CHANGED
@@ -26,6 +26,7 @@ export { default as Dropdown } from "./components/Dropdown";
26
26
  export { default as SelectView } from "./components/SelectView";
27
27
  export { default as DataGrid } from "./components/DataGrid";
28
28
  export * from "./components/DataGrid/typings";
29
+ export { GridApi, ColumnApi } from '@ag-grid-community/core';
29
30
  export * from '@ag-grid-community/react';
30
31
  export { default as BasicLayout } from "./layouts/BasicLayout";
31
32
  export { default as BlankLayout } from "./layouts/BlankLayout";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.0-46",
3
+ "version": "1.0.0-47",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -69,14 +69,13 @@
69
69
  "@types/react-router": "^5.0.0",
70
70
  "@types/react-router-dom": "^5.0.0",
71
71
  "@types/shallowequal": "^1.1.1",
72
- "@umijs/fabric": "^2.8.1",
72
+ "@umijs/fabric": "^2.14.1",
73
73
  "@umijs/test": "^3.0.5",
74
74
  "dumi": "^1.1.0",
75
75
  "father": "^4.0.7",
76
76
  "gh-pages": "^3.0.0",
77
77
  "husky": "^8.0.1",
78
78
  "lint-staged": "^10.0.7",
79
- "prettier": "^2.2.1",
80
79
  "react": "^18.2.0",
81
80
  "react-dom": "^18.2.0"
82
81
  }
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { Store } from './utils';
3
- declare const GridContext: import("react").Context<Store<any>>;
4
- export default GridContext;
@@ -1,4 +0,0 @@
1
- import { createContext } from 'react';
2
- import { Store } from "./utils";
3
- var GridContext = /*#__PURE__*/createContext(new Store({}));
4
- export default GridContext;