@zhenliang/sheet 0.1.98 → 0.1.99-beta.1

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.
@@ -239,6 +239,7 @@ export var sideEffectReducer = {
239
239
  }
240
240
  return _context.abrupt("return");
241
241
  case 9:
242
+ // 获取表格的 col 总数
242
243
  changes = changeInfo.changes, extChanges = changeInfo.extChanges;
243
244
  legalChanges = changes.filter(function (_ref5) {
244
245
  var row = _ref5.row,
@@ -1,5 +1,5 @@
1
1
  import { SheetTableType } from "../..";
2
2
  export declare const useRowSelection: (dataSource: Record<string, unknown>[], rowSelection?: SheetTableType.TableRowSelection, hasChildren?: boolean) => [boolean[], (value: boolean[]) => void];
3
- export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "dataSource" | "rowKey" | "showRemark" | "rowSelection"> & {
3
+ export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "showRemark" | "rowSelection" | "dataSource" | "rowKey"> & {
4
4
  checked: boolean[];
5
5
  }) => any[][];
package/dist/core/util.js CHANGED
@@ -113,7 +113,7 @@ export function clipboardDataToString() {
113
113
  });
114
114
  }
115
115
  export function formatDataToCell(_ref2) {
116
- var _start$row3, _end$row3;
116
+ var _data$, _start$row3, _end$row3;
117
117
  var start = _ref2.start,
118
118
  editing = _ref2.editing,
119
119
  end = _ref2.end,
@@ -124,14 +124,20 @@ export function formatDataToCell(_ref2) {
124
124
  freePaste = _ref2$freePaste === void 0 ? false : _ref2$freePaste;
125
125
  if (editing || !data) return;
126
126
  var cells = flatRowColIndex(start, end);
127
+ var cols = (_data$ = data[0]) !== null && _data$ !== void 0 ? _data$ : [];
128
+ // 获取数组中 editable 为 true 的最后一个元素 的 下标
129
+ var lastCanEditColIndex = -1;
130
+ for (var i = 0; i < cols.length; i++) {
131
+ if (cols[i].editable) {
132
+ lastCanEditColIndex = i;
133
+ }
134
+ }
127
135
  if (!cells.length) return;
128
136
  var rowCount = cells[cells.length - 1].row - cells[0].row + 1;
129
- if (!cells.length) return;
130
137
  var isMultiCells = cells.length > 1;
131
138
  var isSinglePaste = pasteData.length === 1 && pasteData[0].length === 1;
132
139
 
133
- // todo 超出行的处理
134
- // const isExRow = (cells[cells.length - 1].row as number) > (data?.length || 0);
140
+ // todo 超出列的处理
135
141
 
136
142
  var groupMap = groupConfigToGroupMap(groupConfig);
137
143
  var actualRowCount = range((_start$row3 = start === null || start === void 0 ? void 0 : start.row) !== null && _start$row3 !== void 0 ? _start$row3 : 0, ((_end$row3 = end === null || end === void 0 ? void 0 : end.row) !== null && _end$row3 !== void 0 ? _end$row3 : 0) + 1).reduce(function (left, index) {
@@ -170,7 +176,9 @@ export function formatDataToCell(_ref2) {
170
176
  var extChanges = [];
171
177
  var hasStartAndNotOpen = false;
172
178
  pasteData.forEach(function (rowData, i) {
173
- rowData.forEach(function (cell, j) {
179
+ rowData.filter(function (cell, j) {
180
+ return col + j <= lastCanEditColIndex;
181
+ }).forEach(function (cell, j) {
174
182
  if (row + i >= data.length) {
175
183
  var _pasteData$i$j;
176
184
  extChanges.push({
@@ -14,9 +14,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
14
14
  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; }
15
15
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- import { Button, Modal } from 'antd';
17
+ import { Modal } from 'antd';
18
18
  import { cloneDeep, random, range } from 'lodash';
19
- import React, { useCallback, useMemo, useRef, useState } from 'react';
19
+ import React, { useCallback, useRef, useState } from 'react';
20
20
  import { getCascaderEditor, getDateEditor, getNumberEditor, getSelectEditor } from "../core/editor";
21
21
  import Table from "../core/table";
22
22
  import { getSelectorViewer } from "../core/viewer";
@@ -47,15 +47,6 @@ var SelectorOptions = [{
47
47
  value: '3',
48
48
  label: '333333'
49
49
  }];
50
- var getTypeViewer = function getTypeViewer(options) {
51
- var TypeViewer = function TypeViewer(props) {
52
- var _options$find;
53
- return (_options$find = options.find(function (item) {
54
- return item.label === props.value || item.value == props.value;
55
- })) === null || _options$find === void 0 ? void 0 : _options$find.label;
56
- };
57
- return TypeViewer;
58
- };
59
50
  var cascaderOptions = [{
60
51
  value: 'zhejiang',
61
52
  label: 'Zhejiang',
@@ -216,12 +207,8 @@ var App = function App() {
216
207
  _useState2 = _slicedToArray(_useState, 2),
217
208
  state = _useState2[0],
218
209
  setState = _useState2[1];
219
- var _useState3 = useState(SelectorOptions),
220
- _useState4 = _slicedToArray(_useState3, 2),
221
- options = _useState4[0],
222
- setOptions = _useState4[1];
223
210
  var sheetInstance = useRef(null);
224
- var handleChange = useCallback(function (changes, extChange) {
211
+ var handleChange = useCallback(function (changes) {
225
212
  var newState = cloneDeep(state);
226
213
  changes.forEach(function (change) {
227
214
  var row = change.row,
@@ -256,31 +243,12 @@ var App = function App() {
256
243
  }))));
257
244
  setTimeout(function () {
258
245
  var _sheetInstance$curren2, _sheetInstance$curren3;
259
- console.log('select', newState.length + count - 1);
246
+ // console.log('select', newState.length + count - 1);
260
247
  (_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 || _sheetInstance$curren2.selectRow(newState.length + count - 1);
261
- console.log('zoomTO', newState.length + count - 1);
248
+ // console.log('zoomTO', newState.length + count - 1);
262
249
  (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 || _sheetInstance$curren3.zoomTo(newState.length + count - 1);
263
250
  }, 100);
264
251
  }, [state]);
265
- var handleOptionsAdd = useCallback(function () {
266
- setOptions([].concat(_toConsumableArray(options), [{
267
- label: String("newSelect".concat(random(false))),
268
- value: String(random(true))
269
- }]));
270
- }, [options]);
271
- var antColumns = useMemo(function () {
272
- var newColumns = [].concat(columns);
273
- newColumns[4] = _objectSpread(_objectSpread({}, columns[4]), {}, {
274
- render: getTypeViewer(options),
275
- editor: getSelectEditor(options, 'value', /*#__PURE__*/_jsx(Button, {
276
- id: "antColumnAdd",
277
- type: "link",
278
- onClick: handleOptionsAdd,
279
- children: "\u65B0\u589E"
280
- }))
281
- });
282
- return newColumns;
283
- }, [options]);
284
252
  return /*#__PURE__*/_jsx(Table, {
285
253
  freePaste: true,
286
254
  draggable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.98",
3
+ "version": "0.1.99-beta.1",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",