@zhenliang/sheet 0.1.13 → 0.1.15

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,6 @@
1
1
  import { Cascader } from 'antd';
2
2
  import 'antd/es/cascader/style/index.css';
3
+ import { isNil } from 'lodash';
3
4
  import { useMemo } from 'react';
4
5
  import { optionsToValuesFromLabelOrValue, valuesTransferToLabel } from "../../util";
5
6
  import "./index.less";
@@ -25,16 +26,11 @@ var getCascaderEditor = function getCascaderEditor(options, getCustomOptions) {
25
26
  event.stopPropagation();
26
27
  },
27
28
  value: val,
28
- allowClear: true
29
- // allowClear={false}
30
- ,
29
+ allowClear: true,
31
30
  displayRender: function displayRender(label) {
32
31
  return label[label.length - 1];
33
32
  },
34
- onChange: handleChange
35
- // onBlur={handleBlur}
36
- // onKeyDown={handleKeyDown}
37
- ,
33
+ onChange: handleChange,
38
34
  options: customOptions
39
35
  });
40
36
  };
@@ -47,6 +43,9 @@ var getCascaderEditor = function getCascaderEditor(options, getCustomOptions) {
47
43
  return res.length ? res[res.length - 1] : null;
48
44
  };
49
45
  CascaderEditor.checker = function (value) {
46
+ if (isNil(value)) {
47
+ return true;
48
+ }
50
49
  var res = optionsToValuesFromLabelOrValue(options, value);
51
50
  return !!res.length;
52
51
  };
@@ -21,8 +21,8 @@
21
21
  }
22
22
  }
23
23
 
24
- }
24
+ .ant-cascader-menu {
25
+ font-size: 12px;
26
+ }
25
27
 
26
- .ant-cascader-menu {
27
- font-size: 12px;
28
- }
28
+ }
@@ -6,6 +6,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
7
  import { DatePicker } from 'antd';
8
8
  import 'antd/es/date-picker/style/index.css';
9
+ import { isNil } from 'lodash';
9
10
  import moment from 'moment';
10
11
  import { useEffect, useMemo, useRef } from 'react';
11
12
  import "./index.less";
@@ -39,6 +40,9 @@ export var getDateEditor = function getDateEditor(dateProps) {
39
40
  }, dateProps));
40
41
  };
41
42
  DateEditor.checker = function (value) {
43
+ if (isNil(value)) {
44
+ return true;
45
+ }
42
46
  var reg = /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])$/;
43
47
  return reg.test(value);
44
48
  };
@@ -2,5 +2,7 @@ import type { SheetType } from "../../../type";
2
2
  import { InputNumberProps } from 'antd';
3
3
  import 'antd/es/input-number/style/index.css';
4
4
  import './index.less';
5
+ declare type inputProps = Partial<Pick<InputNumberProps, 'max' | 'min' | 'addonBefore' | 'addonAfter' | 'precision'>>;
5
6
  export declare const NumberEditor: SheetType.CellEditor;
6
- export declare const getNumberEditor: (extraProps?: Partial<Pick<InputNumberProps, 'max' | 'min' | 'addonBefore' | 'addonAfter' | 'precision'>>) => SheetType.CellEditor;
7
+ export declare const getNumberEditor: (extraProps?: inputProps, getExtraProps?: ((props: SheetType.CellEditorProps) => inputProps) | undefined) => SheetType.CellEditor;
8
+ export {};
@@ -34,7 +34,7 @@ export var NumberEditor = function NumberEditor(props) {
34
34
  onChange: onChange
35
35
  });
36
36
  };
37
- export var getNumberEditor = function getNumberEditor(extraProps) {
37
+ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps) {
38
38
  var NumberEditor = function NumberEditor(props) {
39
39
  var value = props.value,
40
40
  onChange = props.onChange;
@@ -43,7 +43,7 @@ export var getNumberEditor = function getNumberEditor(extraProps) {
43
43
  var _inputNumberRef$curre2;
44
44
  inputNumberRef === null || inputNumberRef === void 0 ? void 0 : (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 ? void 0 : _inputNumberRef$curre2.focus();
45
45
  }, []);
46
- var _ref = extraProps || {},
46
+ var _ref = getExtraProps ? getExtraProps(props) : extraProps !== null && extraProps !== void 0 ? extraProps : {},
47
47
  precision = _ref.precision,
48
48
  inputArgs = _objectWithoutProperties(_ref, _excluded);
49
49
  var valueFormatter = useCallback(function (value) {
@@ -14,8 +14,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  import { Select } from 'antd';
16
16
  import 'antd/es/select/style/index.css';
17
- import { useState } from 'react';
18
17
  import { isNil } from 'lodash';
18
+ import { useState } from 'react';
19
19
  import "./index.less";
20
20
  import { Fragment as _Fragment } from "react/jsx-runtime";
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -59,7 +59,7 @@ export var getSelectEditor = function getSelectEditor(options) {
59
59
  onMouseDown: function onMouseDown(e) {
60
60
  e.stopPropagation();
61
61
  },
62
- value: SelectEditor.formatter ? SelectEditor.formatter(value) : value,
62
+ value: SelectEditor.parser ? SelectEditor.parser(value) : value,
63
63
  onChange: handleChange,
64
64
  onKeyDown: handleKeyDown,
65
65
  options: customOptions,
@@ -1,10 +1,11 @@
1
- .select-editor,.ant-select-selector {
1
+ .select-editor {
2
2
  // select style
3
3
  width: 100%;
4
4
  line-height: 20px;
5
5
  height: 20px;
6
6
 
7
7
  .ant-select-selector {
8
+ width: 100%;
8
9
  border: none !important;
9
10
  background: transparent !important;
10
11
  box-shadow: none !important;
@@ -36,8 +37,7 @@
36
37
  box-shadow: inset 0 -100px 0 rgba(33,133,208,15%);
37
38
  }
38
39
 
40
+ .ant-select-item {
41
+ font-size: 12px !important;
42
+ }
39
43
  }
40
-
41
- .ant-select-item {
42
- font-size: 12px !important;
43
- }
@@ -138,18 +138,22 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
138
138
 
139
139
  .harvest-sheet-container .harvest-sheet .cell.selected-top{
140
140
  border-top-color: var(--resizer);
141
+ border-top-width: 1px;
141
142
  }
142
143
 
143
144
  .harvest-sheet-container .harvest-sheet .cell.selected-left{
144
145
  border-left-color: var(--resizer);
145
- }
146
+ border-left-width:1px;
147
+ }
146
148
 
147
149
  .harvest-sheet-container .harvest-sheet .cell.selected-bottom{
148
150
  border-bottom-color: var(--resizer);
151
+ border-bottom-width:1px;
149
152
  }
150
153
 
151
154
  .harvest-sheet-container .harvest-sheet .cell.selected-right{
152
155
  border-right-color: var(--resizer);
156
+ border-right-width:1px;
153
157
  }
154
158
 
155
159
 
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { SheetType } from "../../../type";
2
3
  import './index.less';
3
4
  export declare const DraggableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
@@ -115,12 +115,18 @@ export var DraggableShell = function DraggableShell(_ref) {
115
115
  }
116
116
  }, "sheet-control"));
117
117
  }
118
+ var i = 0;
118
119
  columns.forEach(function (item, index) {
119
- var _item$dataIndex2;
120
+ var _item$titleConfig4, _item$dataIndex2;
121
+ var currentWidth = item.width || 'unset';
122
+ if (((_item$titleConfig4 = item.titleConfig) === null || _item$titleConfig4 === void 0 ? void 0 : _item$titleConfig4.colSpan) !== 0) {
123
+ currentWidth = widths[i] || item.width || 'unset';
124
+ i++;
125
+ }
120
126
  cols.push( /*#__PURE__*/_jsx("col", {
121
127
  className: classNames('cell'),
122
128
  style: {
123
- width: widths[index] || item.width || 'unset'
129
+ width: currentWidth
124
130
  }
125
131
  }, (_item$dataIndex2 = item.dataIndex) !== null && _item$dataIndex2 !== void 0 ? _item$dataIndex2 : index));
126
132
  });
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import type { SheetType } from "../../type";
2
3
  import './draggableShell/index.less';
3
4
  export declare const TableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
@@ -122,10 +122,10 @@ var Table = function Table(_ref) {
122
122
  id: rowId,
123
123
  value: value,
124
124
  record: itemRow,
125
- readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex),
125
+ readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex, col),
126
126
  align: colInfo.align,
127
127
  fixed: colInfo.fixed,
128
- editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex),
128
+ editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex, col),
129
129
  valueViewer: colInfo.render ? colInfo.render : undefined,
130
130
  dataEditor: colInfo.editor ? colInfo.editor : undefined,
131
131
  row: currentIndex,
@@ -171,7 +171,7 @@ var Table = function Table(_ref) {
171
171
  id: rowId,
172
172
  value: value,
173
173
  record: item,
174
- readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row),
174
+ readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row, col),
175
175
  align: colInfo.align,
176
176
  fixed: colInfo.fixed,
177
177
  editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, item, row),
@@ -193,6 +193,7 @@ var Table = function Table(_ref) {
193
193
  var handleChanges = useCallback(function (changes, extChange) {
194
194
  onChange && onChange(changes.map(function (item) {
195
195
  return {
196
+ col: item.col,
196
197
  row: item.row,
197
198
  id: item.id,
198
199
  key: columns[hasControl ? item.col - 1 : item.col].dataIndex,
@@ -200,6 +201,7 @@ var Table = function Table(_ref) {
200
201
  };
201
202
  }), extChange === null || extChange === void 0 ? void 0 : extChange.map(function (item) {
202
203
  return {
204
+ col: item.col,
203
205
  row: item.row,
204
206
  id: item.id,
205
207
  key: columns[hasControl ? item.col - 1 : item.col].dataIndex,
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  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; }
5
5
  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; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { flatten } from 'lodash';
7
+ import { flatten, isNil } from 'lodash';
8
8
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
9
  import { dataSourceToRowConfig } from "./util";
10
10
  export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig, hasChildren) {
@@ -30,14 +30,24 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
30
30
  if (groupConfigRef.current) {
31
31
  rowConfig.groups.forEach(function (_ref, index) {
32
32
  var _groupConfigRef$curre, _groupConfigRef$curre2;
33
- var groupName = _ref.groupName;
33
+ var groupName = _ref.groupName,
34
+ newGroupStart = _ref.groupStart,
35
+ newGroupEnd = _ref.groupEnd;
34
36
  var rowIndex = (_groupConfigRef$curre = (_groupConfigRef$curre2 = groupConfigRef.current) === null || _groupConfigRef$curre2 === void 0 ? void 0 : _groupConfigRef$curre2.groups.findIndex(function (item) {
35
37
  return item.groupName === groupName;
36
38
  })) !== null && _groupConfigRef$curre !== void 0 ? _groupConfigRef$curre : -1;
37
39
  if (rowIndex >= 0) {
38
- var _groupConfigRef$curre3, _groupConfigRef$curre4, _groupConfigRef$curre5;
39
- var hasNewLine = rowConfig.groups[rowIndex].groupEnd !== ((_groupConfigRef$curre3 = groupConfigRef.current) === null || _groupConfigRef$curre3 === void 0 ? void 0 : (_groupConfigRef$curre4 = _groupConfigRef$curre3.groups[index]) === null || _groupConfigRef$curre4 === void 0 ? void 0 : _groupConfigRef$curre4.groupEnd);
40
- rowConfig.groupOpen[rowIndex] = hasNewLine ? true : (_groupConfigRef$curre5 = groupConfigRef.current) === null || _groupConfigRef$curre5 === void 0 ? void 0 : _groupConfigRef$curre5.groupOpen[index];
40
+ var _groupConfigRef$curre3, _groupConfigRef$curre4;
41
+ var hasNewLine = false;
42
+ var currentOld = (_groupConfigRef$curre3 = groupConfigRef.current) === null || _groupConfigRef$curre3 === void 0 ? void 0 : _groupConfigRef$curre3.groups[rowIndex];
43
+ if (currentOld && !isNil(currentOld.groupEnd) && !isNil(currentOld.groupStart)) {
44
+ var oldLength = currentOld.groupEnd - currentOld.groupStart;
45
+ var newLength = newGroupEnd - newGroupStart;
46
+ hasNewLine = newLength > oldLength;
47
+ } else {
48
+ hasNewLine = true;
49
+ }
50
+ rowConfig.groupOpen[index] = hasNewLine ? true : (_groupConfigRef$curre4 = groupConfigRef.current) === null || _groupConfigRef$curre4 === void 0 ? void 0 : _groupConfigRef$curre4.groupOpen[rowIndex];
41
51
  } else {
42
52
  // 新子行
43
53
  rowConfig.groupOpen[index] = true;
@@ -48,10 +58,8 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
48
58
  groupConfigRef.current = rowConfig;
49
59
  }, [dataSource.length, childrenLength, hasChildren]);
50
60
  var handleGroupChange = useCallback(function (value) {
51
- var _groupConfigRef$curre6;
52
61
  setGroupConfig(value);
53
62
  groupConfigRef.current = value;
54
- console.log('handler', childrenLength, (_groupConfigRef$curre6 = groupConfigRef.current) === null || _groupConfigRef$curre6 === void 0 ? void 0 : _groupConfigRef$curre6.groupOpen);
55
63
  }, [setGroupConfig]);
56
64
  return [groupConfig, handleGroupChange];
57
65
  };
@@ -5,7 +5,7 @@ export declare type refAssertion = {
5
5
  focus?: () => boolean;
6
6
  } & HTMLTableSectionElement;
7
7
  export declare type CellFixed = SheetType.CellAlign;
8
- export declare type RecordRowMap<T> = (value: unknown, record: Record<string, unknown>, index: number) => T;
8
+ export declare type RecordRowMap<T> = (value: unknown, record: Record<string, unknown>, index: number, colIndex?: number) => T;
9
9
  export declare type ColumnProps = {
10
10
  /**
11
11
  * @description 对齐
@@ -38,6 +38,7 @@ export declare type ColumnProps = {
38
38
  editor?: SheetType.CellEditor;
39
39
  };
40
40
  export declare type TableChange = {
41
+ col?: number;
41
42
  row: number;
42
43
  id: string;
43
44
  key: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",