@fileverse-dev/fortune-core 1.1.37 → 1.1.38

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.
@@ -105,7 +105,7 @@ export function fixPositionOnFrozenCells(freeze, x, y, mouseX, mouseY) {
105
105
  }
106
106
  export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxInput, canvas) {
107
107
  var _a, _b;
108
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
108
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
109
109
  if (!(fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerHTML) && ctx) {
110
110
  ctx.defaultCandidates = [];
111
111
  }
@@ -124,11 +124,11 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
124
124
  return;
125
125
  }
126
126
  var freeze = (_c = globalCache.freezen) === null || _c === void 0 ? void 0 : _c[ctx.currentSheetId];
127
- var _p = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
128
- x = _p.x,
129
- y = _p.y,
130
- inHorizontalFreeze = _p.inHorizontalFreeze,
131
- inVerticalFreeze = _p.inVerticalFreeze;
127
+ var _q = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
128
+ x = _q.x,
129
+ y = _q.y,
130
+ inHorizontalFreeze = _q.inHorizontalFreeze,
131
+ inVerticalFreeze = _q.inVerticalFreeze;
132
132
  var row_location = rowLocation(y, ctx.visibledatarow);
133
133
  var row = row_location[1];
134
134
  var row_pre = row_location[0];
@@ -173,7 +173,11 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
173
173
  }
174
174
  ctx.luckysheet_scroll_status = true;
175
175
  if (ctx.luckysheetCellUpdate.length > 0) {
176
- if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || israngeseleciton(ctx)) {
176
+ var parser = new DOMParser();
177
+ var doc = parser.parseFromString("<div>".concat((_g = document.getElementById("luckysheet-rich-text-editor")) === null || _g === void 0 ? void 0 : _g.innerHTML, "</div>"), "text/html");
178
+ var spans = doc.querySelectorAll("span");
179
+ var firstSpan = spans[0];
180
+ if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || israngeseleciton(ctx) || (firstSpan === null || firstSpan === void 0 ? void 0 : firstSpan.innerText.includes("="))) {
177
181
  var rowseleted = [row_index, row_index_ed];
178
182
  var columnseleted = [col_index, col_index_ed];
179
183
  var left = col_pre;
@@ -240,7 +244,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
240
244
  last.top_move = top_1;
241
245
  last.height_move = height;
242
246
  ctx.formulaCache.func_selectedrange = last;
243
- } else if (e.ctrlKey && ((_g = _.last(cellInput.querySelectorAll("span"))) === null || _g === void 0 ? void 0 : _g.innerText) !== ",") {
247
+ } else if (e.ctrlKey && ((_h = _.last(cellInput.querySelectorAll("span"))) === null || _h === void 0 ? void 0 : _h.innerText) !== ",") {
244
248
  var vText = cellInput.innerText;
245
249
  if (vText[vText.length - 1] === ")") {
246
250
  vText = vText.substring(0, vText.length - 1);
@@ -256,7 +260,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
256
260
  if (window.getSelection) {
257
261
  var currSelection = window.getSelection();
258
262
  if (currSelection == null) return;
259
- ctx.formulaCache.functionRangeIndex = [_.indexOf((_k = (_j = (_h = currSelection.anchorNode) === null || _h === void 0 ? void 0 : _h.parentNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.childNodes, (_l = currSelection.anchorNode) === null || _l === void 0 ? void 0 : _l.parentNode), currSelection.anchorOffset];
263
+ ctx.formulaCache.functionRangeIndex = [_.indexOf((_l = (_k = (_j = currSelection.anchorNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.parentNode) === null || _l === void 0 ? void 0 : _l.childNodes, (_m = currSelection.anchorNode) === null || _m === void 0 ? void 0 : _m.parentNode), currSelection.anchorOffset];
260
264
  } else {
261
265
  var textRange = document.selection.createRange();
262
266
  ctx.formulaCache.functionRangeIndex = textRange;
@@ -330,7 +334,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
330
334
  }
331
335
  if (ctx.luckysheet_select_status) {
332
336
  if (e.shiftKey) {
333
- var last = (_m = ctx.luckysheet_select_save) === null || _m === void 0 ? void 0 : _m[ctx.luckysheet_select_save.length - 1];
337
+ var last = (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o[ctx.luckysheet_select_save.length - 1];
334
338
  if (last && last.top != null && last.left != null && last.height != null && last.width != null && last.row_focus != null && last.column_focus != null) {
335
339
  var top_2 = 0;
336
340
  var height = 0;
@@ -389,7 +393,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
389
393
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
390
394
  }
391
395
  } else if (e.ctrlKey || e.metaKey) {
392
- (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o.push({
396
+ (_p = ctx.luckysheet_select_save) === null || _p === void 0 ? void 0 : _p.push({
393
397
  left: col_pre,
394
398
  width: col - col_pre - 1,
395
399
  top: row_pre,
@@ -29,6 +29,7 @@ import { locale } from "../locale";
29
29
  import { colors } from "./color";
30
30
  import { colLocation, mousePosition, rowLocation } from "./location";
31
31
  import { cancelFunctionrangeSelected, seletedHighlistByindex, spillSortResult } from ".";
32
+ import { isLetterNumberPattern, removeLastSpan } from "./../utils/index";
32
33
  var functionHTMLIndex = 0;
33
34
  var rangeIndexes = [];
34
35
  var operatorPriority = {
@@ -1235,7 +1236,7 @@ export function setCaretPosition(ctx, textDom, children, pos) {
1235
1236
  sel === null || sel === void 0 ? void 0 : sel.addRange(range);
1236
1237
  el.focus();
1237
1238
  } catch (err) {
1238
- console.warn("setCaretPosition error");
1239
+ console.error(err);
1239
1240
  moveToEnd(ctx.formulaCache.rangeResizeTo[0]);
1240
1241
  }
1241
1242
  }
@@ -1938,6 +1939,14 @@ export function functionStrChange(txt, type, rc, orient, stindex, step) {
1938
1939
  }
1939
1940
  export function rangeSetValue(ctx, cellInput, selected, fxInput) {
1940
1941
  var _a, _b, _c, _d, _e;
1942
+ var parser = new DOMParser();
1943
+ var doc = parser.parseFromString("<div>".concat(cellInput.innerHTML, "</div>"), "text/html");
1944
+ var spans = doc.querySelectorAll("span");
1945
+ var lastSpan = spans[spans.length - 1];
1946
+ if (lastSpan && isLetterNumberPattern(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
1947
+ var htmlR = removeLastSpan(cellInput.innerHTML);
1948
+ cellInput.innerHTML = "".concat(htmlR);
1949
+ }
1941
1950
  var $editor = cellInput;
1942
1951
  var $copyTo = fxInput;
1943
1952
  if (((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.id) === "luckysheet-functionbox-cell") {
@@ -17,3 +17,5 @@ export declare function getRegExpStr(str: string): string;
17
17
  export declare function chatatABC(n: number): string;
18
18
  export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
19
19
  export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
20
+ export declare function isLetterNumberPattern(str: string): boolean;
21
+ export declare function removeLastSpan(htmlString: string): string;
package/es/utils/index.js CHANGED
@@ -195,4 +195,18 @@ export function isAllowEditReadOnly(ctx, range) {
195
195
  }
196
196
  return true;
197
197
  }) && (_.isUndefined(ctx.isFlvReadOnly) ? true : ctx.isFlvReadOnly);
198
+ }
199
+ export function isLetterNumberPattern(str) {
200
+ var regex = /^[a-zA-Z]\d+$/;
201
+ return regex.test(str);
202
+ }
203
+ export function removeLastSpan(htmlString) {
204
+ var container = document.createElement("div");
205
+ container.innerHTML = htmlString;
206
+ var spans = container.querySelectorAll("span");
207
+ if (spans.length > 0) {
208
+ var lastSpan = spans[spans.length - 1];
209
+ lastSpan.remove();
210
+ }
211
+ return container.innerHTML;
198
212
  }
@@ -124,7 +124,7 @@ function fixPositionOnFrozenCells(freeze, x, y, mouseX, mouseY) {
124
124
  }
125
125
  function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxInput, canvas) {
126
126
  var _a, _b;
127
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
127
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
128
128
  if (!(fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerHTML) && ctx) {
129
129
  ctx.defaultCandidates = [];
130
130
  }
@@ -143,11 +143,11 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
143
143
  return;
144
144
  }
145
145
  var freeze = (_c = globalCache.freezen) === null || _c === void 0 ? void 0 : _c[ctx.currentSheetId];
146
- var _p = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
147
- x = _p.x,
148
- y = _p.y,
149
- inHorizontalFreeze = _p.inHorizontalFreeze,
150
- inVerticalFreeze = _p.inVerticalFreeze;
146
+ var _q = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
147
+ x = _q.x,
148
+ y = _q.y,
149
+ inHorizontalFreeze = _q.inHorizontalFreeze,
150
+ inVerticalFreeze = _q.inVerticalFreeze;
151
151
  var row_location = (0, _location.rowLocation)(y, ctx.visibledatarow);
152
152
  var row = row_location[1];
153
153
  var row_pre = row_location[0];
@@ -192,7 +192,11 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
192
192
  }
193
193
  ctx.luckysheet_scroll_status = true;
194
194
  if (ctx.luckysheetCellUpdate.length > 0) {
195
- if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || (0, _modules.israngeseleciton)(ctx)) {
195
+ var parser = new DOMParser();
196
+ var doc = parser.parseFromString("<div>".concat((_g = document.getElementById("luckysheet-rich-text-editor")) === null || _g === void 0 ? void 0 : _g.innerHTML, "</div>"), "text/html");
197
+ var spans = doc.querySelectorAll("span");
198
+ var firstSpan = spans[0];
199
+ if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || (0, _modules.israngeseleciton)(ctx) || (firstSpan === null || firstSpan === void 0 ? void 0 : firstSpan.innerText.includes("="))) {
196
200
  var rowseleted = [row_index, row_index_ed];
197
201
  var columnseleted = [col_index, col_index_ed];
198
202
  var left = col_pre;
@@ -259,7 +263,7 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
259
263
  last.top_move = top_1;
260
264
  last.height_move = height;
261
265
  ctx.formulaCache.func_selectedrange = last;
262
- } else if (e.ctrlKey && ((_g = _lodash.default.last(cellInput.querySelectorAll("span"))) === null || _g === void 0 ? void 0 : _g.innerText) !== ",") {
266
+ } else if (e.ctrlKey && ((_h = _lodash.default.last(cellInput.querySelectorAll("span"))) === null || _h === void 0 ? void 0 : _h.innerText) !== ",") {
263
267
  var vText = cellInput.innerText;
264
268
  if (vText[vText.length - 1] === ")") {
265
269
  vText = vText.substring(0, vText.length - 1);
@@ -275,7 +279,7 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
275
279
  if (window.getSelection) {
276
280
  var currSelection = window.getSelection();
277
281
  if (currSelection == null) return;
278
- ctx.formulaCache.functionRangeIndex = [_lodash.default.indexOf((_k = (_j = (_h = currSelection.anchorNode) === null || _h === void 0 ? void 0 : _h.parentNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.childNodes, (_l = currSelection.anchorNode) === null || _l === void 0 ? void 0 : _l.parentNode), currSelection.anchorOffset];
282
+ ctx.formulaCache.functionRangeIndex = [_lodash.default.indexOf((_l = (_k = (_j = currSelection.anchorNode) === null || _j === void 0 ? void 0 : _j.parentNode) === null || _k === void 0 ? void 0 : _k.parentNode) === null || _l === void 0 ? void 0 : _l.childNodes, (_m = currSelection.anchorNode) === null || _m === void 0 ? void 0 : _m.parentNode), currSelection.anchorOffset];
279
283
  } else {
280
284
  var textRange = document.selection.createRange();
281
285
  ctx.formulaCache.functionRangeIndex = textRange;
@@ -349,7 +353,7 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
349
353
  }
350
354
  if (ctx.luckysheet_select_status) {
351
355
  if (e.shiftKey) {
352
- var last = (_m = ctx.luckysheet_select_save) === null || _m === void 0 ? void 0 : _m[ctx.luckysheet_select_save.length - 1];
356
+ var last = (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o[ctx.luckysheet_select_save.length - 1];
353
357
  if (last && last.top != null && last.left != null && last.height != null && last.width != null && last.row_focus != null && last.column_focus != null) {
354
358
  var top_2 = 0;
355
359
  var height = 0;
@@ -408,7 +412,7 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
408
412
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
409
413
  }
410
414
  } else if (e.ctrlKey || e.metaKey) {
411
- (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o.push({
415
+ (_p = ctx.luckysheet_select_save) === null || _p === void 0 ? void 0 : _p.push({
412
416
  left: col_pre,
413
417
  width: col - col_pre - 1,
414
418
  top: row_pre,
@@ -38,6 +38,7 @@ var _locale = require("../locale");
38
38
  var _color = require("./color");
39
39
  var _location = require("./location");
40
40
  var _2 = require(".");
41
+ var _index = require("./../utils/index");
41
42
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
42
43
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
43
44
  var __assign = void 0 && (void 0).__assign || function () {
@@ -1264,7 +1265,7 @@ function setCaretPosition(ctx, textDom, children, pos) {
1264
1265
  sel === null || sel === void 0 ? void 0 : sel.addRange(range);
1265
1266
  el.focus();
1266
1267
  } catch (err) {
1267
- console.warn("setCaretPosition error");
1268
+ console.error(err);
1268
1269
  (0, _cursor.moveToEnd)(ctx.formulaCache.rangeResizeTo[0]);
1269
1270
  }
1270
1271
  }
@@ -1967,6 +1968,14 @@ function functionStrChange(txt, type, rc, orient, stindex, step) {
1967
1968
  }
1968
1969
  function rangeSetValue(ctx, cellInput, selected, fxInput) {
1969
1970
  var _a, _b, _c, _d, _e;
1971
+ var parser = new DOMParser();
1972
+ var doc = parser.parseFromString("<div>".concat(cellInput.innerHTML, "</div>"), "text/html");
1973
+ var spans = doc.querySelectorAll("span");
1974
+ var lastSpan = spans[spans.length - 1];
1975
+ if (lastSpan && (0, _index.isLetterNumberPattern)(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
1976
+ var htmlR = (0, _index.removeLastSpan)(cellInput.innerHTML);
1977
+ cellInput.innerHTML = "".concat(htmlR);
1978
+ }
1970
1979
  var $editor = cellInput;
1971
1980
  var $copyTo = fxInput;
1972
1981
  if (((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.id) === "luckysheet-functionbox-cell") {
@@ -17,3 +17,5 @@ export declare function getRegExpStr(str: string): string;
17
17
  export declare function chatatABC(n: number): string;
18
18
  export declare function isAllowEdit(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
19
19
  export declare function isAllowEditReadOnly(ctx: Context, range?: Sheet["luckysheet_select_save"]): boolean;
20
+ export declare function isLetterNumberPattern(str: string): boolean;
21
+ export declare function removeLastSpan(htmlString: string): string;
@@ -18,7 +18,9 @@ var _exportNames = {
18
18
  getRegExpStr: true,
19
19
  chatatABC: true,
20
20
  isAllowEdit: true,
21
- isAllowEditReadOnly: true
21
+ isAllowEditReadOnly: true,
22
+ isLetterNumberPattern: true,
23
+ removeLastSpan: true
22
24
  };
23
25
  exports.chatatABC = chatatABC;
24
26
  exports.columnCharToIndex = columnCharToIndex;
@@ -33,6 +35,8 @@ exports.getSheetIndex = getSheetIndex;
33
35
  exports.indexToColumnChar = indexToColumnChar;
34
36
  exports.isAllowEdit = isAllowEdit;
35
37
  exports.isAllowEditReadOnly = isAllowEditReadOnly;
38
+ exports.isLetterNumberPattern = isLetterNumberPattern;
39
+ exports.removeLastSpan = removeLastSpan;
36
40
  exports.replaceHtml = replaceHtml;
37
41
  exports.rgbToHex = rgbToHex;
38
42
  var _lodash = _interopRequireDefault(require("lodash"));
@@ -255,4 +259,18 @@ function isAllowEditReadOnly(ctx, range) {
255
259
  }
256
260
  return true;
257
261
  }) && (_lodash.default.isUndefined(ctx.isFlvReadOnly) ? true : ctx.isFlvReadOnly);
262
+ }
263
+ function isLetterNumberPattern(str) {
264
+ var regex = /^[a-zA-Z]\d+$/;
265
+ return regex.test(str);
266
+ }
267
+ function removeLastSpan(htmlString) {
268
+ var container = document.createElement("div");
269
+ container.innerHTML = htmlString;
270
+ var spans = container.querySelectorAll("span");
271
+ if (spans.length > 0) {
272
+ var lastSpan = spans[spans.length - 1];
273
+ lastSpan.remove();
274
+ }
275
+ return container.innerHTML;
258
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.1.37",
3
+ "version": "1.1.38",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",