@fileverse-dev/fortune-core 1.3.10-yjs-10 → 1.3.11-input-ref

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.
@@ -117,13 +117,16 @@ import _ from "lodash";
117
117
  import { hideCRCount, removeActiveImage } from "..";
118
118
  import { getFlowdata } from "../context";
119
119
  import { updateCell, cancelNormalSelected } from "../modules/cell";
120
- import { handleFormulaInput } from "../modules/formula";
120
+ import { handleFormulaInput, israngeseleciton, maybeRecoverDirtyRangeSelection, markRangeSelectionDirty } from "../modules/formula";
121
121
  import { copy, deleteSelectedCellText, deleteSelectedCellFormat, textFormat, fillDate, fillTime, fillRightData, fillDownData, moveHighlightCell, moveHighlightRange, selectAll, selectionCache } from "../modules/selection";
122
122
  import { cancelPaintModel, handleBold, handleItalic, handleUnderline, handleLink } from "../modules/toolbar";
123
123
  import { hasPartMC } from "../modules/validation";
124
124
  import { getNowDateTime, getSheetIndex, isAllowEdit } from "../utils";
125
125
  import { handleCopy } from "./copy";
126
126
  import { jfrefreshgrid } from "../modules/refresh";
127
+ function isLegacyFormulaRangeMode(ctx) {
128
+ return !!ctx.formulaCache.rangestart || !!ctx.formulaCache.rangedrag_column_start || !!ctx.formulaCache.rangedrag_row_start || ctx.formulaCache.rangeSelectionActive === true || israngeseleciton(ctx);
129
+ }
127
130
  export function handleGlobalEnter(ctx, cellInput, e, canvas) {
128
131
  var _a, _b, _c;
129
132
  if ((e.altKey || e.metaKey) && ctx.luckysheetCellUpdate.length > 0) {
@@ -169,11 +172,20 @@ function moveToEdge(sheetData, key, curr, rowDelta, colDelta, startR, endR, star
169
172
  return colDelta === 0 ? r : c;
170
173
  }
171
174
  function handleControlPlusArrowKey(ctx, e, shiftPressed) {
172
- if (ctx.luckysheetCellUpdate.length > 0) return;
175
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
176
+ return;
177
+ }
178
+ var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
179
+ if (isFormulaRefMode) {
180
+ ctx.formulaCache.rangeSelectionActive = true;
181
+ }
182
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
183
+ return;
184
+ }
173
185
  var idx = getSheetIndex(ctx, ctx.currentSheetId);
174
186
  if (_.isNil(idx)) return;
175
187
  var file = ctx.luckysheetfile[idx];
176
- if (!file || !file.row || !file.column) return;
188
+ if (!file || _.isNil(file.row) || _.isNil(file.column)) return;
177
189
  var maxRow = file.row;
178
190
  var maxCol = file.column;
179
191
  var last;
@@ -324,7 +336,14 @@ export function handleWithCtrlOrMetaKey(ctx, cache, e, cellInput, fxInput, handl
324
336
  }
325
337
  function handleShiftWithArrowKey(ctx, e) {
326
338
  var _a;
327
- if (ctx.luckysheetCellUpdate.length > 0) {
339
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
340
+ return;
341
+ }
342
+ var isFormulaMode = isLegacyFormulaRangeMode(ctx);
343
+ if (isFormulaMode) {
344
+ ctx.formulaCache.rangeSelectionActive = true;
345
+ }
346
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaMode) {
328
347
  return;
329
348
  }
330
349
  ctx.luckysheet_shiftpositon = _.cloneDeep((_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1]);
@@ -348,17 +367,15 @@ function handleShiftWithArrowKey(ctx, e) {
348
367
  e.preventDefault();
349
368
  }
350
369
  export function handleArrowKey(ctx, e) {
351
- var _a, _b;
352
- if (ctx.luckysheetCellUpdate.length > 0 || ctx.luckysheet_cell_selected_move || ctx.luckysheet_cell_selected_extend) {
353
- var parser = new DOMParser();
354
- var doc = parser.parseFromString("<div>".concat((_a = document.getElementById("luckysheet-rich-text-editor")) === null || _a === void 0 ? void 0 : _a.innerHTML, "</div>"), "text/html");
355
- var spans = doc.querySelectorAll("span");
356
- var lastSpan = spans[spans.length - 1];
357
- var notFunctionInit = !((_b = document.getElementById("luckysheet-rich-text-editor")) === null || _b === void 0 ? void 0 : _b.innerText.includes("("));
358
- if ((lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")")) || (lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes('"')) || notFunctionInit && /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) && !_.includes(["="], lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText) || /^[a-zA-Z]+$/.test(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText)) {
359
- return;
360
- }
370
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
371
+ return;
361
372
  }
373
+ var isFormulaRefMode = isLegacyFormulaRangeMode(ctx);
374
+ if (isFormulaRefMode) ctx.formulaCache.rangeSelectionActive = true;
375
+ if (ctx.luckysheetCellUpdate.length > 0 && !isFormulaRefMode) {
376
+ return;
377
+ }
378
+ if (ctx.luckysheetCellUpdate.length > 0 || ctx.luckysheet_cell_selected_move || ctx.luckysheet_cell_selected_extend) {}
362
379
  var moveCount = hideCRCount(ctx, e.key);
363
380
  switch (e.key) {
364
381
  case "ArrowUp":
@@ -376,6 +393,7 @@ export function handleArrowKey(ctx, e) {
376
393
  default:
377
394
  break;
378
395
  }
396
+ e.preventDefault();
379
397
  }
380
398
  export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, handleRedo, canvas) {
381
399
  var _a, _b, _c;
@@ -484,6 +502,9 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
484
502
  if (ctx.activeImg != null) {
485
503
  removeActiveImage(ctx);
486
504
  } else {
505
+ if (ctx.formulaCache.rangeSelectionActive === true) {
506
+ markRangeSelectionDirty(ctx);
507
+ }
487
508
  deleteSelectedCellText(ctx);
488
509
  }
489
510
  jfrefreshgrid(ctx, null, undefined);
@@ -1,6 +1,6 @@
1
1
  import _ from "lodash";
2
2
  import { getFlowdata } from "../context";
3
- import { cancelActiveImgItem, cancelPaintModel, functionHTMLGenerate, israngeseleciton, rangeHightlightselected, rangeSetValue, onCommentBoxMove, onCommentBoxMoveEnd, onCommentBoxResize, onCommentBoxResizeEnd, onImageMove, onImageMoveEnd, onImageResize, onImageResizeEnd, removeEditingComment, removeOverShowComment, rangeDrag, onFormulaRangeDragEnd, createFormulaRangeSelect, createRangeHightlight, onCellsMoveEnd, onCellsMove, cellFocus, editComment, onIframeMoveEnd, onIframeResizeEnd, overShowError } from "../modules";
3
+ import { cancelActiveImgItem, cancelPaintModel, functionHTMLGenerate, israngeseleciton, maybeRecoverDirtyRangeSelection, rangeHightlightselected, rangeSetValue, onCommentBoxMove, onCommentBoxMoveEnd, onCommentBoxResize, onCommentBoxResizeEnd, onImageMove, onImageMoveEnd, onImageResize, onImageResizeEnd, removeEditingComment, removeOverShowComment, rangeDrag, onFormulaRangeDragEnd, createFormulaRangeSelect, createRangeHightlight, onCellsMoveEnd, onCellsMove, cellFocus, editComment, onIframeMoveEnd, onIframeResizeEnd, overShowError } from "../modules";
4
4
  import { getFrozenHandleLeft, getFrozenHandleTop, scrollToFrozenRowCol } from "../modules/freeze";
5
5
  import { cancelFunctionrangeSelected, mergeBorder, mergeMoveMain, updateCell, luckysheetUpdateCell } from "../modules/cell";
6
6
  import { colLocation, colLocationByIndex, rowLocation, rowLocationByIndex } from "../modules/location";
@@ -106,7 +106,7 @@ export function fixPositionOnFrozenCells(freeze, x, y, mouseX, mouseY) {
106
106
  }
107
107
  export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxInput, canvas) {
108
108
  var _a, _b;
109
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
109
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
110
110
  if (!(fxInput === null || fxInput === void 0 ? void 0 : fxInput.innerHTML) && ctx) {
111
111
  ctx.defaultCandidates = [];
112
112
  }
@@ -125,11 +125,11 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
125
125
  return;
126
126
  }
127
127
  var freeze = (_c = globalCache.freezen) === null || _c === void 0 ? void 0 : _c[ctx.currentSheetId];
128
- var _q = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
129
- x = _q.x,
130
- y = _q.y,
131
- inHorizontalFreeze = _q.inHorizontalFreeze,
132
- inVerticalFreeze = _q.inVerticalFreeze;
128
+ var _p = fixPositionOnFrozenCells(freeze, _x, _y, mouseX, mouseY),
129
+ x = _p.x,
130
+ y = _p.y,
131
+ inHorizontalFreeze = _p.inHorizontalFreeze,
132
+ inVerticalFreeze = _p.inVerticalFreeze;
133
133
  var row_location = rowLocation(y, ctx.visibledatarow);
134
134
  var row = row_location[1];
135
135
  var row_pre = row_location[0];
@@ -174,12 +174,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
174
174
  }
175
175
  ctx.luckysheet_scroll_status = true;
176
176
  if (ctx.luckysheetCellUpdate.length > 0) {
177
- var parser = new DOMParser();
178
- var doc = parser.parseFromString("<div>".concat((_g = document.getElementById("luckysheet-rich-text-editor")) === null || _g === void 0 ? void 0 : _g.innerHTML, "</div>"), "text/html");
179
- var spans = doc.querySelectorAll("span");
180
- var firstSpan = spans[0];
181
- var lastSpan = spans[spans.length - 1];
182
- 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("=")) && !(lastSpan === null || lastSpan === void 0 ? void 0 : lastSpan.innerText.includes(")"))) && lastSpan && ctx.luckysheetCellUpdate.length === 2) {
177
+ if (ctx.formulaCache.rangestart || ctx.formulaCache.rangedrag_column_start || ctx.formulaCache.rangedrag_row_start || israngeseleciton(ctx)) {
183
178
  var rowseleted = [row_index, row_index_ed];
184
179
  var columnseleted = [col_index, col_index_ed];
185
180
  var left = col_pre;
@@ -246,7 +241,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
246
241
  last.top_move = top_1;
247
242
  last.height_move = height;
248
243
  ctx.formulaCache.func_selectedrange = last;
249
- } else if (e.ctrlKey && ((_h = _.last(cellInput.querySelectorAll("span"))) === null || _h === void 0 ? void 0 : _h.innerText) !== ",") {
244
+ } else if (e.ctrlKey && ((_g = _.last(cellInput.querySelectorAll("span"))) === null || _g === void 0 ? void 0 : _g.innerText) !== ",") {
250
245
  var vText = cellInput.innerText;
251
246
  if (vText[vText.length - 1] === ")") {
252
247
  vText = vText.substring(0, vText.length - 1);
@@ -262,7 +257,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
262
257
  if (window.getSelection) {
263
258
  var currSelection = window.getSelection();
264
259
  if (currSelection == null) return;
265
- 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
+ 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];
266
261
  } else {
267
262
  var textRange = document.selection.createRange();
268
263
  ctx.formulaCache.functionRangeIndex = textRange;
@@ -307,13 +302,14 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
307
302
  column_focus: col_index
308
303
  };
309
304
  }
305
+ ctx.formulaCache.rangestart = true;
306
+ ctx.formulaCache.rangedrag_column_start = false;
307
+ ctx.formulaCache.rangedrag_row_start = false;
310
308
  rangeSetValue(ctx, cellInput, {
311
309
  row: rowseleted,
312
310
  column: columnseleted
313
311
  }, fxInput);
314
- ctx.formulaCache.rangestart = true;
315
- ctx.formulaCache.rangedrag_column_start = false;
316
- ctx.formulaCache.rangedrag_row_start = false;
312
+ rangeHightlightselected(ctx, cellInput);
317
313
  ctx.formulaCache.selectingRangeIndex = ctx.formulaCache.rangechangeindex;
318
314
  if (ctx.formulaCache.rangechangeindex > ctx.formulaRangeHighlight.length) {
319
315
  createRangeHightlight(ctx, cellInput.innerHTML, ctx.formulaCache.rangechangeindex);
@@ -336,7 +332,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
336
332
  }
337
333
  if (ctx.luckysheet_select_status) {
338
334
  if (e.shiftKey) {
339
- var last = (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o[ctx.luckysheet_select_save.length - 1];
335
+ var last = (_m = ctx.luckysheet_select_save) === null || _m === void 0 ? void 0 : _m[ctx.luckysheet_select_save.length - 1];
340
336
  if (last && last.top != null && last.left != null && last.height != null && last.width != null && last.row_focus != null && last.column_focus != null) {
341
337
  var top_2 = 0;
342
338
  var height = 0;
@@ -395,7 +391,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
395
391
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
396
392
  }
397
393
  } else if (e.ctrlKey || e.metaKey) {
398
- (_p = ctx.luckysheet_select_save) === null || _p === void 0 ? void 0 : _p.push({
394
+ (_o = ctx.luckysheet_select_save) === null || _o === void 0 ? void 0 : _o.push({
399
395
  left: col_pre,
400
396
  width: col - col_pre - 1,
401
397
  top: row_pre,
@@ -827,10 +823,28 @@ export function mouseRender(ctx, globalCache, e, cellInput, scrollX, scrollY, co
827
823
  ctx.luckysheet_select_save[ctx.luckysheet_select_save.length - 1] = last;
828
824
  scrollToFrozenRowCol(ctx, (_d = globalCache.freezen) === null || _d === void 0 ? void 0 : _d[ctx.currentSheetId]);
829
825
  } else if (ctx.formulaCache.rangestart) {
826
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
827
+ if (ctx.luckysheetCellUpdate.length > 0) {
828
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
829
+ }
830
+ return;
831
+ }
830
832
  rangeDrag(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
831
833
  } else if (ctx.formulaCache.rangedrag_row_start) {
834
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
835
+ if (ctx.luckysheetCellUpdate.length > 0) {
836
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
837
+ }
838
+ return;
839
+ }
832
840
  rangeDragRow(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
833
841
  } else if (ctx.formulaCache.rangedrag_column_start) {
842
+ if (ctx.formulaCache.rangeSelectionActive === false && !maybeRecoverDirtyRangeSelection(ctx)) {
843
+ if (ctx.luckysheetCellUpdate.length > 0) {
844
+ updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput);
845
+ }
846
+ return;
847
+ }
834
848
  rangeDragColumn(ctx, e, cellInput, scrollX.scrollLeft, scrollY.scrollTop, container, fxInput);
835
849
  } else if (ctx.luckysheet_rows_selected_status) {} else if (ctx.luckysheet_cols_selected_status) {} else if (ctx.luckysheet_cell_selected_move) {} else if (ctx.luckysheet_cell_selected_extend) {
836
850
  onDropCellSelect(ctx, e, scrollX, scrollY, container);
@@ -1317,6 +1331,7 @@ export function handleRowHeaderMouseDown(ctx, globalCache, e, container, cellInp
1317
1331
  row: rowseleted,
1318
1332
  column: [null, null]
1319
1333
  }, fxInput);
1334
+ rangeHightlightselected(ctx, cellInput);
1320
1335
  }
1321
1336
  ctx.formulaCache.rangedrag_row_start = true;
1322
1337
  ctx.formulaCache.rangestart = false;
@@ -1548,6 +1563,7 @@ export function handleColumnHeaderMouseDown(ctx, globalCache, e, container, cell
1548
1563
  row: [null, null],
1549
1564
  column: columnseleted
1550
1565
  }, fxInput);
1566
+ rangeHightlightselected(ctx, cellInput);
1551
1567
  }
1552
1568
  ctx.formulaCache.rangedrag_column_start = true;
1553
1569
  ctx.formulaCache.rangestart = false;
@@ -541,6 +541,7 @@ export function cancelNormalSelected(ctx) {
541
541
  ctx.formulaCache.rangestart = false;
542
542
  ctx.formulaCache.rangedrag_column_start = false;
543
543
  ctx.formulaCache.rangedrag_row_start = false;
544
+ ctx.formulaCache.rangeSelectionActive = null;
544
545
  }
545
546
  export function updateCell(ctx, r, c, $input, value, canvas) {
546
547
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
@@ -1780,7 +1780,6 @@ function getApplyData(copyD, csLen, asLen) {
1780
1780
  export function updateDropCell(ctx) {
1781
1781
  var _a, _b, _c, _d;
1782
1782
  var _e, _f, _g, _h;
1783
- console.log("updateDropCell");
1784
1783
  var d = getFlowdata(ctx);
1785
1784
  var allowEdit = isAllowEdit(ctx);
1786
1785
  var isReadOnly = isAllowEditReadOnly(ctx);
@@ -20,6 +20,7 @@ export declare class FormulaCache {
20
20
  rangetosheet?: string;
21
21
  rangedrag_column_start?: boolean;
22
22
  rangedrag_row_start?: boolean;
23
+ rangeSelectionActive?: boolean | null;
23
24
  functionRangeIndex?: number[];
24
25
  functionlistMap: any;
25
26
  execFunctionExist?: any[];
@@ -44,8 +45,14 @@ export declare function setCaretPosition(ctx: Context, textDom: HTMLElement, chi
44
45
  export declare function getrangeseleciton(): ParentNode | ChildNode | null | undefined;
45
46
  export declare function rangeHightlightselected(ctx: Context, $editor: HTMLDivElement): void;
46
47
  export declare function functionHTMLGenerate(txt: string): string;
48
+ export declare function getLastFormulaRangeIndex($editor: HTMLDivElement): number | null;
49
+ export declare function getFormulaRangeIndexAtCaret($editor: HTMLDivElement): number | null;
50
+ export declare function markRangeSelectionDirty(ctx: Context): void;
51
+ export declare function getFormulaRangeIndexForKeyboardSync($editor: HTMLDivElement): number | null;
47
52
  export declare function handleFormulaInput(ctx: Context, $copyTo: HTMLDivElement | null | undefined, $editor: HTMLDivElement, kcode: number, preText?: string, refreshRangeSelect?: boolean): void;
48
53
  export declare function israngeseleciton(ctx: Context, istooltip?: boolean): boolean;
54
+ export declare function isFormulaReferenceInputMode(ctx: Context): boolean;
55
+ export declare function maybeRecoverDirtyRangeSelection(ctx: Context): boolean;
49
56
  export declare function functionStrChange(txt: string, type: string, rc: "row" | "col", orient: string | null, stindex: number, step: number): string;
50
57
  export declare function rangeSetValue(ctx: Context, cellInput: HTMLDivElement, selected: any, fxInput?: HTMLDivElement | null): void;
51
58
  export declare function onFormulaRangeDragEnd(ctx: Context): void;