@zhenliang/sheet 0.2.5-beta.1 → 0.2.5-beta.2
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.
|
@@ -12,7 +12,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
12
12
|
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; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
14
|
import { Dropdown, Menu, Tooltip } from 'antd';
|
|
15
|
-
import { head, isEmpty, isNil } from 'lodash';
|
|
15
|
+
import { get, head, isEmpty, isNil } from 'lodash';
|
|
16
16
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
17
17
|
import { InfoCircleOutlined } from '@ant-design/icons';
|
|
18
18
|
import { flattenOptions, getStringDiff, replaceLabelsWithValues, replaceLongestDiff, replaceValuesWithLabels, tokenize, validateVariables, getCursorPositionInSpan } from "./utils";
|
|
@@ -34,11 +34,12 @@ var getSpanAtCursor = function getSpanAtCursor(startContainer) {
|
|
|
34
34
|
};
|
|
35
35
|
export var getFormulaInputEditor = function getFormulaInputEditor(options, replaceIndex) {
|
|
36
36
|
var FormulaInputEditor = function FormulaInputEditor(props) {
|
|
37
|
+
var _get;
|
|
37
38
|
var originValue = props.value,
|
|
38
39
|
onChange = props.onChange,
|
|
39
40
|
isEditing = props.isEditing,
|
|
40
41
|
record = props.record;
|
|
41
|
-
var calcValue = replaceIndex ? record
|
|
42
|
+
var calcValue = replaceIndex ? "".concat((_get = get(record, [replaceIndex])) !== null && _get !== void 0 ? _get : '') : originValue;
|
|
42
43
|
var _useState = useState(calcValue),
|
|
43
44
|
_useState2 = _slicedToArray(_useState, 1),
|
|
44
45
|
inputValue = _useState2[0];
|
|
@@ -216,7 +217,7 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
216
217
|
if (open) {
|
|
217
218
|
var _getStringDiff2 = getStringDiff(containerValueSnapShot.current, newValue),
|
|
218
219
|
addedOnSnapShot = _getStringDiff2.added;
|
|
219
|
-
isBeginWithNumber = /^\d$/.test(head(addedOnSnapShot));
|
|
220
|
+
isBeginWithNumber = /^\d$/.test(head(addedOnSnapShot.join('').trim()));
|
|
220
221
|
inputStringAfterDropDownShow = addedOnSnapShot.join('');
|
|
221
222
|
}
|
|
222
223
|
if (pressAOperator) {
|
|
@@ -371,6 +372,16 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
371
372
|
|
|
372
373
|
// 删除键逻辑
|
|
373
374
|
if (e.key !== 'Delete' && e.key !== 'Backspace') return;
|
|
375
|
+
if (e.key === 'Backspace') {
|
|
376
|
+
// 检查删除后是否只剩一个空的 span
|
|
377
|
+
var allSpansNow = Array.from(div.querySelectorAll('span'));
|
|
378
|
+
var isOnlyOneEmptySpan = allSpansNow.length === 1 && allSpansNow[0].textContent === '';
|
|
379
|
+
if (isOnlyOneEmptySpan) {
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
e.stopPropagation();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
374
385
|
|
|
375
386
|
// 不在 label span 内,在 span 开头且前一个是 label 时,删除整个 label span
|
|
376
387
|
if (startOffset === 0 && e.key === 'Backspace' && currentIndex > 0) {
|
|
@@ -571,13 +582,13 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
571
582
|
spellCheck: false,
|
|
572
583
|
children: isEmpty(tokens) ? /*#__PURE__*/_jsx("span", {
|
|
573
584
|
style: {
|
|
574
|
-
minWidth:
|
|
585
|
+
minWidth: 1,
|
|
575
586
|
height: 40
|
|
576
587
|
}
|
|
577
588
|
}) : tokens.map(function (token, index) {
|
|
578
589
|
return token.type === 'end' ? /*#__PURE__*/_jsx("span", {
|
|
579
590
|
style: {
|
|
580
|
-
minWidth:
|
|
591
|
+
minWidth: 1,
|
|
581
592
|
height: 40
|
|
582
593
|
}
|
|
583
594
|
}, index) : /*#__PURE__*/_jsx("span", {
|
|
@@ -115,6 +115,9 @@ var splitSegmentByLabels = function splitSegmentByLabels(segment, sortedLabels)
|
|
|
115
115
|
* 有效 label 为 type 'label',其他为 'other'
|
|
116
116
|
*/
|
|
117
117
|
export var tokenize = function tokenize(text, flatOptions) {
|
|
118
|
+
if (!text) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
118
121
|
var tokens = [];
|
|
119
122
|
|
|
120
123
|
// 将 value 转换为 label
|
|
@@ -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" | "
|
|
3
|
+
export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "showRemark" | "rowSelection" | "dataSource" | "rowKey"> & {
|
|
4
4
|
checked: boolean[];
|
|
5
5
|
}) => any[][];
|
package/dist/example/basic.js
CHANGED
|
@@ -175,6 +175,14 @@ var data = [{
|
|
|
175
175
|
tags: ['cool', 'teacher'],
|
|
176
176
|
formula: '=(123 + 456) * price + 888',
|
|
177
177
|
amount: 100
|
|
178
|
+
}, {
|
|
179
|
+
key: '6',
|
|
180
|
+
name: 'Joe 23',
|
|
181
|
+
age: 41,
|
|
182
|
+
address: 'Sidney No. 1 Lake Park',
|
|
183
|
+
tags: ['cool', 'teacher'],
|
|
184
|
+
formula: null,
|
|
185
|
+
amount: 100
|
|
178
186
|
}];
|
|
179
187
|
var App = function App() {
|
|
180
188
|
var _useState = useState(data),
|