@zhenliang/sheet 0.2.5-beta.13 → 0.2.5-beta.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.
@@ -8,7 +8,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
8
8
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
9
  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; }
10
10
  import { useCallback, useMemo } from 'react';
11
- import { getCursorPositionInSpan, getSpanAtCursor, moveCursorToSpan } from "./utils";
11
+ import { createSpan, getCursorPositionInSpan, getSpanAtCursor, moveCursorToSpan, SpanType } from "./utils";
12
12
  var useKeyEventEffect = function useKeyEventEffect(_ref) {
13
13
  var closeDorpDown = _ref.closeDorpDown,
14
14
  setOffsetX = _ref.setOffsetX,
@@ -55,7 +55,7 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
55
55
  }, [closeDorpDown, setOffsetX, setOpen]);
56
56
  var handleKeyDown = useCallback(function (e) {
57
57
  var _currentSpan$textCont, _currentSpan$textCont2;
58
- if (e.key === 'ArrowUp' || e.key === 'ArrowDown' || e.key === 'Delete') {
58
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
59
59
  e.preventDefault();
60
60
  e.stopPropagation();
61
61
  return;
@@ -123,17 +123,14 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
123
123
  }
124
124
  return;
125
125
  }
126
-
126
+ var isDeleteOpt = e.key === 'Backspace' || e.key === 'Delete';
127
127
  // 删除键逻辑
128
- if (e.key !== 'Delete' && e.key !== 'Backspace') return;
129
- if (e.key === 'Backspace' || e.key === 'Delete') {
128
+ if (!isDeleteOpt) return;
129
+ if (isDeleteOpt) {
130
130
  if (tempSpanRef.current) {
131
131
  closeDorpDown();
132
132
  }
133
- // 检查删除后是否只剩一个空的 span
134
- var allSpansNow = Array.from(div.querySelectorAll('span'));
135
- var isOnlyOneEmptySpan = allSpansNow.length === 1 && allSpansNow[0].textContent === '';
136
- if (isOnlyOneEmptySpan) {
133
+ if (!div.textContent || div.textContent === '') {
137
134
  e.preventDefault();
138
135
  e.stopPropagation();
139
136
  return;
@@ -141,7 +138,7 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
141
138
  }
142
139
 
143
140
  // 不在 label span 内,在 span 开头且前一个是 label 时,删除整个 label span
144
- if (startOffset === 0 && e.key === 'Backspace' && currentIndex > 0) {
141
+ if (startOffset === 0 && e.key === 'BackSpace' && currentIndex > 0) {
145
142
  var prevSpan = allSpans[currentIndex - 1];
146
143
  if (prevSpan.classList.contains('formula-editor-token-label')) {
147
144
  e.preventDefault();
@@ -177,7 +174,7 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
177
174
  }
178
175
 
179
176
  // 在 span 开头 + Delete 键,光标移到前一个 span 的末尾
180
- if (startOffset === 0 && e.key === 'Backspace' && currentIndex > 0) {
177
+ if (startOffset === 0 && e.key === 'BackSpace' && currentIndex > 0) {
181
178
  var _prevSpan = allSpans[currentIndex - 1];
182
179
  // 前一个 span 是非 label span 时,光标移到其末尾
183
180
  if (!_prevSpan.classList.contains('formula-editor-token-label')) {
@@ -227,7 +224,13 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
227
224
  return;
228
225
  }
229
226
  }
230
- if (!currentSpanNow || currentSpanNow === div) return;
227
+ if (!currentSpanNow || currentSpanNow === div) {
228
+ // 插入一个空的 other span
229
+ var emptySpan = createSpan(SpanType.OTHER, '');
230
+ div.appendChild(emptySpan);
231
+ moveCursorToSpan(emptySpan, true, selection);
232
+ return;
233
+ }
231
234
  if (currentSpanNow.textContent === '') {
232
235
  var currentIndexNow = allSpansNow.indexOf(currentSpanNow);
233
236
  var _newRange = document.createRange();
@@ -6,7 +6,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { ExclamationCircleOutlined } from '@ant-design/icons';
8
8
  import { Modal } from 'antd';
9
- import { isNil } from 'lodash';
9
+ import { get, isNil } from 'lodash';
10
10
  import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
11
  import { useSetState, useSheetEvent } from "../../hooks";
12
12
  import { renderValue } from "../util";
@@ -30,6 +30,7 @@ var Cell = function Cell(props) {
30
30
  valueViewer = props.valueViewer,
31
31
  attributesRenderer = props.attributesRenderer,
32
32
  cellFixedInfo = props.cellFixedInfo;
33
+ var replaceIndex = cell.replaceIndex;
33
34
  var eventBus = useSheetEvent();
34
35
  var _useSetState = useSetState(),
35
36
  _useSetState2 = _slicedToArray(_useSetState, 2),
@@ -82,8 +83,9 @@ var Cell = function Cell(props) {
82
83
  setEventState({
83
84
  confirm: false
84
85
  });
86
+ var oldValue = replaceIndex ? get(cell.record, [replaceIndex(cell.record)]) : valueRef.current;
85
87
  var newValue = value;
86
- if (newValue === valueRef.current) {
88
+ if (newValue === oldValue) {
87
89
  return;
88
90
  }
89
91
  // 转化一下公式
@@ -165,6 +165,7 @@ export var formatGroupData = function formatGroupData(param) {
165
165
  valueViewer: colInfo.render ? colInfo.render : undefined,
166
166
  dataEditor: colInfo.editor ? colInfo.editor : undefined,
167
167
  searchKey: colInfo.searchKey,
168
+ replaceIndex: colInfo.replaceIndex,
168
169
  row: currentIndex,
169
170
  className: classNames(!(((_colInfo$cellConfig = colInfo.cellConfig) === null || _colInfo$cellConfig === void 0 ? void 0 : _colInfo$cellConfig.className) instanceof Function) ? (_colInfo$cellConfig2 = colInfo.cellConfig) === null || _colInfo$cellConfig2 === void 0 ? void 0 : _colInfo$cellConfig2.className : (_colInfo$cellConfig3 = colInfo.cellConfig) === null || _colInfo$cellConfig3 === void 0 ? void 0 : _colInfo$cellConfig3.className(value, itemRow, currentIndex), hasRemark ? 'remark-cell' : null),
170
171
  dataIndex: colInfo.dataIndex,
@@ -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, "dataSource" | "columns" | "rowKey" | "showRemark" | "rowSelection"> & {
3
+ export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "dataSource" | "rowKey" | "showRemark" | "rowSelection"> & {
4
4
  checked: boolean[];
5
5
  }) => any[][];
@@ -82,6 +82,7 @@ export var formatSelectionData = function formatSelectionData(param) {
82
82
  valueViewer: colInfo.render ? colInfo.render : undefined,
83
83
  dataEditor: colInfo.editor ? colInfo.editor : undefined,
84
84
  searchKey: colInfo.searchKey,
85
+ replaceIndex: colInfo.replaceIndex,
85
86
  className: classNames(!(((_colInfo$cellConfig = colInfo.cellConfig) === null || _colInfo$cellConfig === void 0 ? void 0 : _colInfo$cellConfig.className) instanceof Function) ? (_colInfo$cellConfig2 = colInfo.cellConfig) === null || _colInfo$cellConfig2 === void 0 ? void 0 : _colInfo$cellConfig2.className : (_colInfo$cellConfig3 = colInfo.cellConfig) === null || _colInfo$cellConfig3 === void 0 ? void 0 : _colInfo$cellConfig3.className(value, item, row), hasRemark ? 'remark-cell' : null),
86
87
  row: row,
87
88
  col: col,
@@ -92,7 +92,10 @@ var columns = [{
92
92
  label: '批发价',
93
93
  value: 'wholesale'
94
94
  }]
95
- }], 'formula')
95
+ }], 'formula'),
96
+ replaceIndex: function replaceIndex(record) {
97
+ return 'formula';
98
+ }
96
99
  }, {
97
100
  title: 'Address',
98
101
  editable: false,
@@ -26,6 +26,7 @@ export type Cell = {
26
26
  dataIndex?: string;
27
27
  valueViewer?: CellViewer;
28
28
  searchKey?: (value: unknown, record?: unknown) => string;
29
+ replaceIndex?: (record?: unknown) => string;
29
30
  className?: string;
30
31
  align?: CellAlign;
31
32
  fixed?: Omit<CellAlign, 'center'>;
@@ -40,6 +40,7 @@ export type ColumnProps = {
40
40
  render?: SheetType.CellViewer;
41
41
  editor?: SheetType.CellEditor;
42
42
  searchKey?: (value: unknown, record: Record<string, unknown>) => string;
43
+ replaceIndex?: (record?: unknown) => string;
43
44
  fixedAllowSelect?: boolean | RecordRowMap<boolean>;
44
45
  };
45
46
  export type TableChange = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.2.5-beta.13",
3
+ "version": "0.2.5-beta.14",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",