@zhenliang/sheet 0.1.12 → 0.1.14

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
  };
@@ -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
  };
@@ -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,
@@ -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
  });
@@ -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
40
  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
+ 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$curre5;
52
61
  setGroupConfig(value);
53
62
  groupConfigRef.current = value;
54
- console.log('handler', childrenLength, (_groupConfigRef$curre5 = groupConfigRef.current) === null || _groupConfigRef$curre5 === void 0 ? void 0 : _groupConfigRef$curre5.groupOpen);
55
63
  }, [setGroupConfig]);
56
64
  return [groupConfig, handleGroupChange];
57
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",