@lemon-fe/kits 1.0.9 → 1.0.10

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,12 @@
1
+ /// <reference types="react" />
2
+ import type { AgGridReactProps } from '@ag-grid-community/react';
3
+ import type { FilterProps } from '../Filter/typings';
4
+ interface ContextProps {
5
+ /** 目前DataGrid由于是类组件,比较难处理,只支持ag-grid自带的属性 */
6
+ DataGrid?: Omit<AgGridReactProps<any>, 'rowSelection' | 'pagination'>;
7
+ Filter?: FilterProps<any>;
8
+ }
9
+ export declare const ComponentConfigureContext: import("react").Context<ContextProps>;
10
+ export declare const ComponentConfigureProvider: import("react").Provider<ContextProps>;
11
+ export declare const ComponentConfigureConsumer: import("react").Consumer<ContextProps>;
12
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ export var ComponentConfigureContext = /*#__PURE__*/createContext({});
3
+ export var ComponentConfigureProvider = ComponentConfigureContext.Provider;
4
+ export var ComponentConfigureConsumer = ComponentConfigureContext.Consumer;
@@ -1,4 +1,4 @@
1
- import type { ColDef, IRowNode } from '@ag-grid-community/core';
1
+ import type { IRowNode } from '@ag-grid-community/core';
2
2
  import { GridApi, ColumnApi } from '@ag-grid-community/core';
3
3
  import React, { Component } from 'react';
4
4
  import EditorWrapper from './cell-editors/Wrapper';
@@ -19,32 +19,8 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
19
19
  private searchRef;
20
20
  private prevFocusedCell;
21
21
  private fields;
22
- static defaultProps: {
23
- stopEditingWhenCellsLoseFocus: boolean;
24
- autoLoad: boolean;
25
- localeText: {
26
- copy: string;
27
- copyWithHeaders: string;
28
- copyWithGroupHeaders: string;
29
- paste: string;
30
- export: string;
31
- csvExport: string;
32
- searchOoo: string;
33
- autosizeThiscolumn: string;
34
- autosizeAllColumns: string;
35
- resetColumns: string;
36
- pinColumn: string;
37
- pinLeft: string;
38
- pinRight: string;
39
- noPin: string;
40
- expandAll: string;
41
- collapseAll: string;
42
- columns: string;
43
- };
44
- columnTypes: Record<string, ColDef<any>>;
45
- defaultColDef: ColDef<any>;
46
- components: Record<string, any>;
47
- };
22
+ static contextType?: React.Context<any> | undefined;
23
+ static defaultProps: Partial<DataGridProps<any>>;
48
24
  static SummaryFlag: symbol;
49
25
  static IndexColId: string;
50
26
  static EmptyCol: ColType<any>;
@@ -52,7 +28,7 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
52
28
  Text: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").TextEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
53
29
  Date: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").DateEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
54
30
  Number: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").NumberEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
55
- Select: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "allowClear" | "mode" | "options" | "virtual" | "showSearch" | "listHeight"> & {
31
+ Select: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "mode" | "showSearch" | "allowClear" | "options" | "virtual" | "listHeight"> & {
56
32
  fieldNames?: {
57
33
  label: string;
58
34
  value: string;
@@ -76,6 +76,7 @@ import { get, set } from 'lodash';
76
76
  import memoizeOne from 'memoize-one';
77
77
  import React, { Component, createRef } from 'react';
78
78
  import shallowEqual from 'shallowequal';
79
+ import { ComponentConfigureContext } from "../ComponentConfigure";
79
80
  import DateEditor from "./cell-editors/Date";
80
81
  import NumberEditor from "./cell-editors/Number";
81
82
  import RowEditor, { RowEditorData } from "./cell-editors/Row";
@@ -1300,7 +1301,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1300
1301
  };
1301
1302
 
1302
1303
  fieldCol.valueFormatter = function (params) {
1303
- if (Number.isNaN(params.value) || !Number.isFinite(params.value) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1304
+ if (Number.isNaN(params.value) || typeof params.value === 'number' && !Number.isFinite(params.value) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1304
1305
  return '-';
1305
1306
  }
1306
1307
 
@@ -1804,27 +1805,29 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1804
1805
  var _this12 = this,
1805
1806
  _classNames;
1806
1807
 
1807
- var _this$props8 = this.props,
1808
- rowKey = _this$props8.rowKey,
1809
- fetch = _this$props8.fetch,
1810
- dataSource = _this$props8.dataSource,
1811
- rowActions = _this$props8.rowActions,
1812
- columns = _this$props8.columns,
1813
- autoLoad = _this$props8.autoLoad,
1814
- loadingProp = _this$props8.loading,
1815
- summary = _this$props8.summary,
1816
- detailCell = _this$props8.detailCell,
1817
- pagination = _this$props8.pagination,
1818
- rowSelection = _this$props8.rowSelection,
1819
- columnTypesProp = _this$props8.columnTypes,
1820
- defaultColDefProp = _this$props8.defaultColDef,
1821
- componentsProp = _this$props8.components,
1822
- sideBarProp = _this$props8.sideBar,
1823
- detailCellRendererParams = _this$props8.detailCellRendererParams,
1824
- context = _this$props8.context,
1825
- showSearch = _this$props8.showSearch,
1826
- cellDisplayFlex = _this$props8.cellDisplayFlex,
1827
- restProps = _objectWithoutProperties(_this$props8, _excluded4);
1808
+ var reactCtx = this.context;
1809
+
1810
+ var _reactCtx$DataGrid$th = _objectSpread(_objectSpread({}, reactCtx.DataGrid), this.props),
1811
+ rowKey = _reactCtx$DataGrid$th.rowKey,
1812
+ fetch = _reactCtx$DataGrid$th.fetch,
1813
+ dataSource = _reactCtx$DataGrid$th.dataSource,
1814
+ rowActions = _reactCtx$DataGrid$th.rowActions,
1815
+ columns = _reactCtx$DataGrid$th.columns,
1816
+ autoLoad = _reactCtx$DataGrid$th.autoLoad,
1817
+ loadingProp = _reactCtx$DataGrid$th.loading,
1818
+ summary = _reactCtx$DataGrid$th.summary,
1819
+ detailCell = _reactCtx$DataGrid$th.detailCell,
1820
+ pagination = _reactCtx$DataGrid$th.pagination,
1821
+ rowSelection = _reactCtx$DataGrid$th.rowSelection,
1822
+ columnTypesProp = _reactCtx$DataGrid$th.columnTypes,
1823
+ defaultColDefProp = _reactCtx$DataGrid$th.defaultColDef,
1824
+ componentsProp = _reactCtx$DataGrid$th.components,
1825
+ sideBarProp = _reactCtx$DataGrid$th.sideBar,
1826
+ detailCellRendererParams = _reactCtx$DataGrid$th.detailCellRendererParams,
1827
+ context = _reactCtx$DataGrid$th.context,
1828
+ showSearch = _reactCtx$DataGrid$th.showSearch,
1829
+ cellDisplayFlex = _reactCtx$DataGrid$th.cellDisplayFlex,
1830
+ restProps = _objectWithoutProperties(_reactCtx$DataGrid$th, _excluded4);
1828
1831
 
1829
1832
  var _this$state2 = this.state,
1830
1833
  enablePagination = _this$state2.pagination,
@@ -1956,6 +1959,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1956
1959
  return DataGrid;
1957
1960
  }(Component);
1958
1961
 
1962
+ _defineProperty(DataGrid, "contextType", ComponentConfigureContext);
1963
+
1959
1964
  _defineProperty(DataGrid, "defaultProps", {
1960
1965
  stopEditingWhenCellsLoseFocus: true,
1961
1966
  autoLoad: false,
@@ -1977,10 +1982,7 @@ _defineProperty(DataGrid, "defaultProps", {
1977
1982
  expandAll: '展开所有',
1978
1983
  collapseAll: '折叠所有',
1979
1984
  columns: '列'
1980
- },
1981
- columnTypes: {},
1982
- defaultColDef: {},
1983
- components: {}
1985
+ }
1984
1986
  });
1985
1987
 
1986
1988
  _defineProperty(DataGrid, "SummaryFlag", Symbol('summary'));
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { ComponentOption, FilterProps } from './typings';
3
- declare function Filter<T extends Record<string, any> = Record<string, any>>(props: FilterProps<T>): JSX.Element;
4
- declare namespace Filter {
3
+ declare function FilterWrapper<T extends Record<string, any> = Record<string, any>>(props: FilterProps<T>): JSX.Element;
4
+ declare namespace FilterWrapper {
5
5
  var setComponents: (items: ComponentOption[]) => void;
6
6
  var setStorage: <T extends {
7
7
  title: string;
@@ -12,4 +12,4 @@ declare namespace Filter {
12
12
  }) => void | Promise<void>) => void;
13
13
  var defaultProps: Partial<FilterProps<Record<string, any>>>;
14
14
  }
15
- export default Filter;
15
+ export default FilterWrapper;
@@ -38,7 +38,8 @@ import { useDebounce, useRequest } from '@lemon-fe/hooks';
38
38
  import { Button, Checkbox, Form, Input, Popover, Space, Modal, message, Select, Empty } from 'antd';
39
39
  import classNames from 'classnames';
40
40
  import ResizeObserver from 'rc-resize-observer';
41
- import React, { useEffect, useMemo, useState } from 'react';
41
+ import React, { useEffect, useMemo, useState, useContext } from 'react';
42
+ import { ComponentConfigureContext } from "../ComponentConfigure";
42
43
  import Dropdown from "../Dropdown";
43
44
  import DurationPicker from "../DurationPicker";
44
45
  import FormLayout from "../FormLayout";
@@ -130,7 +131,8 @@ function Filter(props) {
130
131
  autoPlaceholder = props.autoPlaceholder,
131
132
  _props$preserveFields = props.preserveFields,
132
133
  preserveFields = _props$preserveFields === void 0 ? true : _props$preserveFields,
133
- legacyReset = props.legacyReset;
134
+ legacyReset = props.legacyReset,
135
+ componentOptions = props.componentOptions;
134
136
  var prefix = prefixClassName('filter');
135
137
  var emptyValue = useMemo(function () {
136
138
  return Object.fromEntries(data.map(function (item) {
@@ -148,10 +150,18 @@ function Filter(props) {
148
150
  return null;
149
151
  }, []);
150
152
  var compMap = useMemo(function () {
151
- return new Map(components.map(function (item) {
153
+ var result = new Map(components.map(function (item) {
152
154
  return [item.type, item];
153
155
  }));
154
- }, []);
156
+
157
+ if (componentOptions) {
158
+ componentOptions.forEach(function (item) {
159
+ result.set(item.type, item);
160
+ });
161
+ }
162
+
163
+ return result;
164
+ }, [componentOptions]);
155
165
 
156
166
  var _useState = useState(defaultKeys),
157
167
  _useState2 = _slicedToArray(_useState, 2),
@@ -491,7 +501,7 @@ function Filter(props) {
491
501
  }
492
502
 
493
503
  return [getSet(result.slice(0, end)), btnsVisible];
494
- }, [data, width, collapsed, activeKeys]),
504
+ }, [data, width, collapsed, activeKeys, compMap]),
495
505
  _useMemo2 = _slicedToArray(_useMemo, 2),
496
506
  cols = _useMemo2[0],
497
507
  showCollapse = _useMemo2[1];
@@ -697,7 +707,12 @@ function Filter(props) {
697
707
  }))))))))));
698
708
  }
699
709
 
700
- Filter.setComponents = setComponents;
701
- Filter.setStorage = setStorage;
702
- Filter.defaultProps = {};
703
- export default Filter;
710
+ function FilterWrapper(props) {
711
+ var contextProps = useContext(ComponentConfigureContext).Filter;
712
+ return /*#__PURE__*/React.createElement(Filter, _extends({}, contextProps, props));
713
+ }
714
+
715
+ FilterWrapper.setComponents = setComponents;
716
+ FilterWrapper.setStorage = setStorage;
717
+ FilterWrapper.defaultProps = {};
718
+ export default FilterWrapper;
@@ -60,6 +60,7 @@ export interface FilterProps<T extends Record<string, any> = Record<string, any>
60
60
  * 当前reset行为是通过内部的emptyValue以及defaultValue
61
61
  */
62
62
  legacyReset?: true;
63
+ componentOptions?: ComponentOption[];
63
64
  }
64
65
 
65
66
  export interface ComponentOption {
package/es/index.d.ts CHANGED
@@ -52,3 +52,4 @@ export { default as Breadcrumb } from './layouts/Breadcrumb';
52
52
  export { default as useBatchOperator } from './hooks/useBatchOperator';
53
53
  export { default as useHistoryBlock } from './hooks/useHistoryBlock';
54
54
  export { TabInstance } from './layouts/TabInstance';
55
+ export * from './components/ComponentConfigure';
package/es/index.js CHANGED
@@ -43,4 +43,5 @@ export { default as MicroLayout } from "./layouts/MicroLayout";
43
43
  export { default as Breadcrumb } from "./layouts/Breadcrumb";
44
44
  export { default as useBatchOperator } from "./hooks/useBatchOperator";
45
45
  export { default as useHistoryBlock } from "./hooks/useHistoryBlock";
46
- export { TabInstance } from "./layouts/TabInstance";
46
+ export { TabInstance } from "./layouts/TabInstance";
47
+ export * from "./components/ComponentConfigure";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",