@zhenliang/sheet 0.1.9 → 0.1.12

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.
@@ -1,5 +1,5 @@
1
1
  import type { SheetType } from "../../../type";
2
2
  import 'antd/es/cascader/style/index.css';
3
3
  import './index.less';
4
- declare const getCascaderEditor: (options: SheetType.OptionsType[]) => SheetType.CellEditor;
4
+ declare const getCascaderEditor: (options: SheetType.OptionsType[], getCustomOptions?: ((props: SheetType.CellEditorProps) => SheetType.OptionsType[]) | undefined) => SheetType.CellEditor;
5
5
  export default getCascaderEditor;
@@ -4,17 +4,19 @@ import { useMemo } from 'react';
4
4
  import { optionsToValuesFromLabelOrValue, valuesTransferToLabel } from "../../util";
5
5
  import "./index.less";
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
7
- var getCascaderEditor = function getCascaderEditor(options) {
7
+ var getCascaderEditor = function getCascaderEditor(options, getCustomOptions) {
8
8
  var CascaderEditor = function CascaderEditor(props) {
9
9
  var value = props.value,
10
10
  onConfirm = props.onConfirm;
11
11
  var val = useMemo(function () {
12
12
  var res = optionsToValuesFromLabelOrValue(options, value);
13
+ console.log('cascader-editor', options, res, value);
13
14
  return res;
14
15
  }, [value, options]);
15
16
  var handleChange = function handleChange(opt) {
16
17
  onConfirm(opt ? opt[opt.length - 1] : null);
17
18
  };
19
+ var customOptions = getCustomOptions ? getCustomOptions(props) : options;
18
20
  return /*#__PURE__*/_jsx(Cascader, {
19
21
  autoFocus: true,
20
22
  open: true,
@@ -22,7 +24,8 @@ var getCascaderEditor = function getCascaderEditor(options) {
22
24
  onMouseDown: function onMouseDown(event) {
23
25
  event.stopPropagation();
24
26
  },
25
- value: val
27
+ value: val,
28
+ allowClear: true
26
29
  // allowClear={false}
27
30
  ,
28
31
  displayRender: function displayRender(label) {
@@ -32,7 +35,7 @@ var getCascaderEditor = function getCascaderEditor(options) {
32
35
  // onBlur={handleBlur}
33
36
  // onKeyDown={handleKeyDown}
34
37
  ,
35
- options: options
38
+ options: customOptions
36
39
  });
37
40
  };
38
41
  CascaderEditor.formatter = function (value) {
@@ -3,6 +3,7 @@
3
3
  background: transparent !important;
4
4
  width:100%;
5
5
  height: 38px;
6
+ height: 100%;
6
7
  font-size: 12px;
7
8
  box-shadow: none !important;
8
9
  text-align: inherit !important;
@@ -2,5 +2,5 @@ import type { SheetType } from "../../../type";
2
2
  import { SelectProps } from 'antd';
3
3
  import 'antd/es/select/style/index.css';
4
4
  import './index.less';
5
- export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode, selectProps?: Partial<SelectProps>) => SheetType.CellEditor;
5
+ export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode, selectProps?: Partial<SelectProps>, getCustomOptions?: ((props: SheetType.CellEditorProps) => SheetType.Options[]) | undefined) => SheetType.CellEditor;
6
6
  export default getSelectEditor;
@@ -24,6 +24,7 @@ export var getSelectEditor = function getSelectEditor(options) {
24
24
  var valueKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
25
25
  var extra = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : /*#__PURE__*/_jsx(_Fragment, {});
26
26
  var selectProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
27
+ var getCustomOptions = arguments.length > 4 ? arguments[4] : undefined;
27
28
  var SelectEditor = function SelectEditor(props) {
28
29
  var _useState = useState(true),
29
30
  _useState2 = _slicedToArray(_useState, 2),
@@ -49,6 +50,7 @@ export var getSelectEditor = function getSelectEditor(options) {
49
50
  children: [menu, extra]
50
51
  });
51
52
  };
53
+ var customOptions = getCustomOptions ? getCustomOptions(props) : options;
52
54
  return /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread({}, selectProps), {}, {
53
55
  autoFocus: true,
54
56
  className: "select-editor",
@@ -60,7 +62,7 @@ export var getSelectEditor = function getSelectEditor(options) {
60
62
  value: SelectEditor.formatter ? SelectEditor.formatter(value) : value,
61
63
  onChange: handleChange,
62
64
  onKeyDown: handleKeyDown,
63
- options: options,
65
+ options: customOptions,
64
66
  popupClassName: 'excelTablePopupClassName',
65
67
  dropdownRender: dropdown
66
68
  }));
@@ -213,12 +213,10 @@ export var sideEffectReducer = {
213
213
  case 9:
214
214
  changes = changeInfo.changes, extChanges = changeInfo.extChanges;
215
215
  legalChanges = changes.filter(function (_ref5) {
216
- var _editor$checker;
217
216
  var row = _ref5.row,
218
217
  col = _ref5.col,
219
218
  value = _ref5.value;
220
219
  var editor = data[row][col].dataEditor;
221
- console.log('number-checker', editor === null || editor === void 0 ? void 0 : editor.checker, editor === null || editor === void 0 ? void 0 : (_editor$checker = editor.checker) === null || _editor$checker === void 0 ? void 0 : _editor$checker.call(editor, value));
222
220
  if (editor && editor.checker) {
223
221
  return editor.checker(value, data[row][col].record);
224
222
  }
@@ -236,7 +234,6 @@ export var sideEffectReducer = {
236
234
  value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 ? void 0 : (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value) : value
237
235
  };
238
236
  });
239
- console.log('number', changes, legalChanges);
240
237
  lastRow = extChanges === null || extChanges === void 0 ? void 0 : (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
241
238
  lastIndex = 1;
242
239
  legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref7) {
@@ -286,7 +283,7 @@ export var sideEffectReducer = {
286
283
  }
287
284
  });
288
285
  cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : []);
289
- case 19:
286
+ case 18:
290
287
  case "end":
291
288
  return _context.stop();
292
289
  }
@@ -116,7 +116,7 @@ export var stateReducer = {
116
116
  });
117
117
  if (lastFixed) {
118
118
  var _state$data$0$indexOf, _state$data7;
119
- endCol = (_state$data$0$indexOf = (_state$data7 = state.data) === null || _state$data7 === void 0 ? void 0 : _state$data7[0].indexOf(lastFixed)) !== null && _state$data$0$indexOf !== void 0 ? _state$data$0$indexOf : 0 - 1;
119
+ endCol = ((_state$data$0$indexOf = (_state$data7 = state.data) === null || _state$data7 === void 0 ? void 0 : _state$data7[0].indexOf(lastFixed)) !== null && _state$data$0$indexOf !== void 0 ? _state$data$0$indexOf : 0) - 1;
120
120
  }
121
121
  if (startCol >= 0 && endCol >= 0) {
122
122
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -70,7 +70,7 @@ var Cell = function Cell(props) {
70
70
  } else if (eventInfo.value && eventInfo.editing) {
71
71
  var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
72
72
  // 单元格直接键盘编辑,设置为输入值
73
- setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 ? void 0 : (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 ? void 0 : (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value) : value);
73
+ setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 ? void 0 : (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 ? void 0 : (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value) : eventInfo.value);
74
74
  }
75
75
  setEventState(eventInfo);
76
76
  };
@@ -115,7 +115,7 @@ var Cell = function Cell(props) {
115
115
  if (valueRef.current === value) {
116
116
  return;
117
117
  }
118
- if (cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
118
+ if (value !== null && cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
119
119
  setValue(valueRef.current);
120
120
  return;
121
121
  }
@@ -11,7 +11,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
11
11
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
12
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { useEffect, useMemo, useRef } from 'react';
14
- import ReduxLogger from 'redux-logger';
14
+ // import ReduxLogger from 'redux-logger';
15
15
  import ReduxThunk from 'redux-thunk';
16
16
  import DefaultRow from "./DefaultRow";
17
17
  import DefaultShell from "./DefaultShell";
@@ -43,6 +43,7 @@ var Sheet = function Sheet(props) {
43
43
  ContextMenu = props.menuRenderer,
44
44
  _props$virtualized = props.virtualized,
45
45
  virtualized = _props$virtualized === void 0 ? false : _props$virtualized,
46
+ sticky = props.sticky,
46
47
  className = props.className,
47
48
  data = props.data,
48
49
  _props$freePaste = props.freePaste,
@@ -66,7 +67,9 @@ var Sheet = function Sheet(props) {
66
67
  lastFocus: [],
67
68
  groupConfig: groupConfig,
68
69
  eventBus: eventBus
69
- }, [ReduxThunk, ReduxLogger]),
70
+ },
71
+ // [ReduxThunk, ReduxLogger],
72
+ [ReduxThunk]),
70
73
  _useMiddlewareReducer2 = _slicedToArray(_useMiddlewareReducer, 2),
71
74
  state = _useMiddlewareReducer2[0],
72
75
  dispatch = _useMiddlewareReducer2[1];
@@ -101,8 +101,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
101
101
 
102
102
 
103
103
  &.fixed-right{
104
- // transform: translateX(1px);
105
-
104
+ transform: translateX(1px);
106
105
  }
107
106
 
108
107
  &.fixed-right::after{
@@ -235,7 +235,6 @@ var Table = function Table(_ref) {
235
235
  }));
236
236
  var headSelection = !!rowSelection;
237
237
  var WrappedTableShell = useMemo(function () {
238
- console.log('shell-render', '损耗性能大');
239
238
  if (draggable) {
240
239
  return DraggableShell({
241
240
  columns: columns,
@@ -28,21 +28,30 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
28
28
  if (!hasChildren) return;
29
29
  var rowConfig = dataSourceToRowConfig(dataSource, tableGroupConfig === null || tableGroupConfig === void 0 ? void 0 : tableGroupConfig.defaultOpen);
30
30
  if (groupConfigRef.current) {
31
- groupConfigRef.current.groups.forEach(function (_ref, index) {
32
- var _groupConfigRef$curre;
31
+ rowConfig.groups.forEach(function (_ref, index) {
32
+ var _groupConfigRef$curre, _groupConfigRef$curre2;
33
33
  var groupName = _ref.groupName;
34
- var rowIndex = rowConfig.groups.findIndex(function (item) {
34
+ var rowIndex = (_groupConfigRef$curre = (_groupConfigRef$curre2 = groupConfigRef.current) === null || _groupConfigRef$curre2 === void 0 ? void 0 : _groupConfigRef$curre2.groups.findIndex(function (item) {
35
35
  return item.groupName === groupName;
36
- });
37
- rowConfig.groupOpen[rowIndex] = ((_groupConfigRef$curre = groupConfigRef.current) === null || _groupConfigRef$curre === void 0 ? void 0 : _groupConfigRef$curre.groupOpen[index]) || rowConfig.groupOpen[rowIndex];
36
+ })) !== null && _groupConfigRef$curre !== void 0 ? _groupConfigRef$curre : -1;
37
+ if (rowIndex >= 0) {
38
+ var _groupConfigRef$curre3, _groupConfigRef$curre4;
39
+ var hasNewLine = rowConfig.groups[rowIndex].groupEnd !== ((_groupConfigRef$curre3 = groupConfigRef.current) === null || _groupConfigRef$curre3 === void 0 ? void 0 : _groupConfigRef$curre3.groups[index].groupEnd);
40
+ rowConfig.groupOpen[rowIndex] = hasNewLine ? true : (_groupConfigRef$curre4 = groupConfigRef.current) === null || _groupConfigRef$curre4 === void 0 ? void 0 : _groupConfigRef$curre4.groupOpen[index];
41
+ } else {
42
+ // 新子行
43
+ rowConfig.groupOpen[index] = true;
44
+ }
38
45
  });
39
46
  }
40
47
  setGroupConfig(rowConfig);
41
48
  groupConfigRef.current = rowConfig;
42
49
  }, [dataSource.length, childrenLength, hasChildren]);
43
50
  var handleGroupChange = useCallback(function (value) {
51
+ var _groupConfigRef$curre5;
44
52
  setGroupConfig(value);
45
53
  groupConfigRef.current = value;
54
+ console.log('handler', childrenLength, (_groupConfigRef$curre5 = groupConfigRef.current) === null || _groupConfigRef$curre5 === void 0 ? void 0 : _groupConfigRef$curre5.groupOpen);
46
55
  }, [setGroupConfig]);
47
56
  return [groupConfig, handleGroupChange];
48
57
  };
@@ -31,7 +31,7 @@ export declare const defaultValueRenderer: (cell: SheetType.Cell) => string | nu
31
31
  export declare function renderValue(cell: SheetType.Cell): string | number;
32
32
  export declare const optionsToValuesFromLabelOrValue: (options: SheetType.OptionsType[], val: string) => string[];
33
33
  export declare const optionsTransferToValue: (options: SheetType.OptionsType[], val: string, key?: string) => string[];
34
- export declare const optionsTransferToValue2: (options?: SheetType.OptionsType[], value?: string, path?: string[]) => string[];
34
+ export declare const optionsTransferToValue2: (options?: SheetType.OptionsType[], value?: string, path?: string[]) => (string | number)[];
35
35
  export declare const valuesTransferToLabel: (options?: SheetType.OptionsType[], value?: string) => string | null;
36
36
  export declare const groupConfigToGroupMap: (rowGroupConfig?: SheetType.RowGroupConfig) => Map<number, SheetType.RowGroup & {
37
37
  isStart: boolean;
@@ -20,6 +20,9 @@ export var GroupViewer = function GroupViewer(props) {
20
20
  }, [eventBus, row, record === null || record === void 0 ? void 0 : record.open]);
21
21
  if (value) {
22
22
  return /*#__PURE__*/_jsx("span", {
23
+ style: {
24
+ cursor: 'pointer'
25
+ },
23
26
  onMouseDown: function onMouseDown(e) {
24
27
  return e.stopPropagation();
25
28
  },
@@ -96,6 +96,7 @@ export declare type SheetProps = {
96
96
  virtualized?: boolean;
97
97
  showBackEdit?: boolean;
98
98
  backEditStyle?: Partial<CSSStyleDeclaration>;
99
+ sticky?: boolean;
99
100
  groupConfig?: RowGroupConfig;
100
101
  onCellsChanged?: CellChangeHandler;
101
102
  menuRenderer?: React.FC<MenuRenderProps>;
@@ -185,7 +186,7 @@ export declare type UpdateStateType = {
185
186
  };
186
187
  export declare type UpdateFocus = (start: CellPosition, end: CellPosition) => void;
187
188
  export declare type Options<T = any> = {
188
- value: string;
189
+ value: string | number;
189
190
  label: string;
190
191
  } & T;
191
192
  export declare type OptionsType = Options<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",