@fileverse-dev/fortune-core 1.3.4 → 1.3.5-hyper-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.
package/es/api/sheet.js CHANGED
@@ -1,3 +1,14 @@
1
+ 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); }
2
+ var __assign = this && this.__assign || function () {
3
+ __assign = Object.assign || function (t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import _ from "lodash";
2
13
  import { v4 as uuidv4 } from "uuid";
3
14
  import { dataToCelldata, getSheet } from "./common";
@@ -135,6 +146,7 @@ function generateCopySheetName(ctx, sheetId) {
135
146
  return sheetCopyName;
136
147
  }
137
148
  export function copySheet(ctx, sheetId) {
149
+ var _a, _b, _c;
138
150
  var index = getSheetIndex(ctx, sheetId);
139
151
  var order = ctx.luckysheetfile[index].order + 1;
140
152
  var sheetName = generateCopySheetName(ctx, sheetId);
@@ -144,8 +156,32 @@ export function copySheet(ctx, sheetId) {
144
156
  sheetData.celldata = dataToCelldata(sheetData.data);
145
157
  delete sheetData.data;
146
158
  api.addSheet(ctx, undefined, uuidv4(), ctx.luckysheetfile[index].isPivotTable, sheetName, sheetData);
159
+ var newSheetIndex = ctx.luckysheetfile.length - 1;
160
+ var newSheet = ctx.luckysheetfile[newSheetIndex];
161
+ var newSheetId = newSheet.id;
162
+ if ((_a = newSheet.calcChain) === null || _a === void 0 ? void 0 : _a.length) {
163
+ newSheet.calcChain = newSheet.calcChain.map(function (entry) {
164
+ return __assign(__assign({}, entry), {
165
+ id: newSheetId
166
+ });
167
+ });
168
+ }
169
+ if ((_b = newSheet.dynamicArray) === null || _b === void 0 ? void 0 : _b.length) {
170
+ newSheet.dynamicArray = newSheet.dynamicArray.map(function (entry) {
171
+ return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
172
+ id: newSheetId
173
+ }) : entry;
174
+ });
175
+ }
176
+ if ((_c = newSheet.dynamicArray_compute) === null || _c === void 0 ? void 0 : _c.length) {
177
+ newSheet.dynamicArray_compute = newSheet.dynamicArray_compute.map(function (entry) {
178
+ return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
179
+ id: newSheetId
180
+ }) : entry;
181
+ });
182
+ }
147
183
  var sheetOrderList = {};
148
- sheetOrderList[ctx.luckysheetfile[ctx.luckysheetfile.length - 1].id] = order;
184
+ sheetOrderList[newSheetId] = order;
149
185
  api.setSheetOrder(ctx, sheetOrderList);
150
186
  }
151
187
  export function calculateSheetFromula(ctx, id) {
@@ -139,7 +139,7 @@ export function handleGlobalEnter(ctx, cellInput, e, canvas) {
139
139
  row_focus: lastCellUpdate[0],
140
140
  column_focus: lastCellUpdate[1]
141
141
  }];
142
- moveHighlightCell(ctx, "down", 1, "rangeOfSelect");
142
+ moveHighlightCell(ctx, "down", hideCRCount(ctx, "ArrowDown"), "rangeOfSelect");
143
143
  e.preventDefault();
144
144
  } else {
145
145
  if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
@@ -396,7 +396,7 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
396
396
  textFormat(ctx, "right");
397
397
  }
398
398
  if ((e.metaKey || e.ctrlKey) && e.code === "KeyK") {
399
- handleLink(ctx);
399
+ handleLink(ctx, cellInput);
400
400
  }
401
401
  if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.code === "Semicolon") {
402
402
  fillDate(ctx);
@@ -434,9 +434,9 @@ export function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUnd
434
434
  updateCell(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
435
435
  }
436
436
  if (e.shiftKey) {
437
- moveHighlightCell(ctx, "right", -1, "rangeOfSelect");
437
+ moveHighlightCell(ctx, "right", -hideCRCount(ctx, "ArrowLeft"), "rangeOfSelect");
438
438
  } else {
439
- moveHighlightCell(ctx, "right", 1, "rangeOfSelect");
439
+ moveHighlightCell(ctx, "right", hideCRCount(ctx, "ArrowRight"), "rangeOfSelect");
440
440
  }
441
441
  e.preventDefault();
442
442
  } else if (kstr === "F2") {
@@ -145,7 +145,7 @@ export function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, containe
145
145
  _a = margeset.row, row_pre = _a[0], row = _a[1], row_index = _a[2], row_index_ed = _a[3];
146
146
  _b = margeset.column, col_pre = _b[0], col = _b[1], col_index = _b[2], col_index_ed = _b[3];
147
147
  }
148
- showLinkCard(ctx, row_index, col_index, false, true);
148
+ showLinkCard(ctx, row_index, col_index, undefined, false, true);
149
149
  if (((_e = (_d = ctx.hooks).beforeCellMouseDown) === null || _e === void 0 ? void 0 : _e.call(_d, (_f = flowdata[row_index]) === null || _f === void 0 ? void 0 : _f[col_index], {
150
150
  row: row_index,
151
151
  column: col_index,
@@ -78,11 +78,9 @@ export function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow)
78
78
  var rowOffset = destRow - srcRow;
79
79
  var hadInvalid = false;
80
80
  var cellRefRegex = /\b(\$?)([A-Z]+)(\$?)(\d+)\b/g;
81
- var stringOrCellRef = /"(?:\\.|[^"])*"|(?<!\$)([A-Z]+\d+\b)/g;
81
+ var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
82
82
  var result = formula.replace(stringOrCellRef, function (m, cellRef) {
83
83
  if (!cellRef) return m;
84
- if (cellRef.startsWith("$")) return m;
85
- console.log(m, "cellRef", cellRef);
86
84
  return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
87
85
  var colIndex = columnLabelIndex(colLetters);
88
86
  var rowIndex = parseInt(rowNum, 10);
@@ -1011,9 +1009,10 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
1011
1009
  if (!_.isNil(value) && !_.isNil(value.f)) {
1012
1010
  var adjustedFormula = value.f;
1013
1011
  var isError = false;
1012
+ var srcRow = c_r1 + (h - mth);
1013
+ var srcCol = c_c1 + (c - mtc);
1014
1014
  try {
1015
- adjustedFormula = adjustFormulaForPaste(value.f, c_c1, c_r1, c, h);
1016
- console.log("adjustedFormula", adjustedFormula);
1015
+ adjustedFormula = adjustFormulaForPaste(value.f, srcCol, srcRow, c, h);
1017
1016
  } catch (error) {
1018
1017
  isError = true;
1019
1018
  value.error = {
@@ -1122,10 +1122,16 @@ export function getInlineStringHTML(r, c, data) {
1122
1122
  var strObj = strings[i];
1123
1123
  if (strObj.v) {
1124
1124
  var style = getFontStyleByCell(strObj);
1125
+ var link = strObj.link;
1126
+ if ((link === null || link === void 0 ? void 0 : link.linkType) && (link === null || link === void 0 ? void 0 : link.linkAddress)) {
1127
+ style.color = style.color || "rgb(0, 0, 255)";
1128
+ style.borderBottom = style.borderBottom || "1px solid rgb(0, 0, 255)";
1129
+ }
1125
1130
  var styleStr = _.map(style, function (v, key) {
1126
1131
  return "".concat(_.kebabCase(key), ":").concat(_.isNumber(v) ? "".concat(v, "px") : v, ";");
1127
1132
  }).join("");
1128
- value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'>").concat(strObj.v, "</span>");
1133
+ var dataAttrs = (link === null || link === void 0 ? void 0 : link.linkType) && (link === null || link === void 0 ? void 0 : link.linkAddress) ? " data-link-type='".concat(String(link.linkType).replace(/'/g, "&#39;"), "' data-link-address='").concat(String(link.linkAddress).replace(/'/g, "&#39;"), "'") : "";
1134
+ value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(strObj.v, "</span>");
1129
1135
  }
1130
1136
  }
1131
1137
  return value;
@@ -1,3 +1,8 @@
1
1
  export declare function moveToEnd(obj: HTMLDivElement): void;
2
2
  export declare function selectTextContent(ele: HTMLElement): void;
3
3
  export declare function selectTextContentCross(sEle: HTMLElement, eEle: HTMLElement): void;
4
+ export declare function getSelectionCharacterOffsets(element: Node): {
5
+ start: number;
6
+ end: number;
7
+ } | null;
8
+ export declare function setSelectionByCharacterOffset(element: HTMLDivElement, start: number, end: number): void;
@@ -59,4 +59,59 @@ export function selectTextContentCross(sEle, eEle) {
59
59
  }
60
60
  }
61
61
  }
62
+ }
63
+ export function getSelectionCharacterOffsets(element) {
64
+ var sel = window.getSelection();
65
+ if (!sel || sel.rangeCount === 0) return null;
66
+ var range = sel.getRangeAt(0);
67
+ if (range.collapsed) return null;
68
+ if (!element.contains(range.startContainer) || !element.contains(range.endContainer)) {
69
+ return null;
70
+ }
71
+ var pre = document.createRange();
72
+ pre.selectNodeContents(element);
73
+ pre.setEnd(range.startContainer, range.startOffset);
74
+ var start = pre.toString().length;
75
+ return {
76
+ start: start,
77
+ end: start + range.toString().length
78
+ };
79
+ }
80
+ export function setSelectionByCharacterOffset(element, start, end) {
81
+ element.focus();
82
+ var sel = window.getSelection();
83
+ if (!sel) return;
84
+ var charIndex = 0;
85
+ var startNode = null;
86
+ var startOffset = 0;
87
+ var endNode = null;
88
+ var endOffset = 0;
89
+ function walk(node) {
90
+ if (node.nodeType === Node.TEXT_NODE) {
91
+ var len = (node.textContent || "").length;
92
+ if (startNode == null && charIndex + len > start) {
93
+ startNode = node;
94
+ startOffset = start - charIndex;
95
+ }
96
+ if (endNode == null && charIndex + len >= end) {
97
+ endNode = node;
98
+ endOffset = end - charIndex;
99
+ return true;
100
+ }
101
+ charIndex += len;
102
+ return false;
103
+ }
104
+ for (var i = 0; i < node.childNodes.length; i += 1) {
105
+ if (walk(node.childNodes[i])) return true;
106
+ }
107
+ return false;
108
+ }
109
+ walk(element);
110
+ if (startNode && endNode) {
111
+ var range = document.createRange();
112
+ range.setStart(startNode, startOffset);
113
+ range.setEnd(endNode, endOffset);
114
+ sel.removeAllRanges();
115
+ sel.addRange(range);
116
+ }
62
117
  }
@@ -8,9 +8,19 @@ export declare function getCellHyperlink(ctx: Context, r: number, c: number): {
8
8
  linkType: string;
9
9
  linkAddress: string;
10
10
  } | undefined;
11
- export declare function saveHyperlink(ctx: Context, r: number, c: number, linkText: string, linkType: string, linkAddress: string): void;
11
+ export declare function saveHyperlink(ctx: Context, r: number, c: number, linkText: string, linkType: string, linkAddress: string, options?: {
12
+ applyToSelection?: boolean;
13
+ cellInput?: HTMLDivElement | null;
14
+ }): void;
12
15
  export declare function removeHyperlink(ctx: Context, r: number, c: number): void;
13
- export declare function showLinkCard(ctx: Context, r: number, c: number, isEditing?: boolean, isMouseDown?: boolean): void;
16
+ export declare function showLinkCard(ctx: Context, r: number, c: number, options?: {
17
+ applyToSelection?: boolean;
18
+ originText?: string;
19
+ selectionOffsets?: {
20
+ start: number;
21
+ end: number;
22
+ };
23
+ }, isEditing?: boolean, isMouseDown?: boolean): void;
14
24
  export declare function goToLink(ctx: Context, r: number, c: number, linkType: string, linkAddress: string, scrollbarX: HTMLDivElement, scrollbarY: HTMLDivElement): void;
15
25
  export declare function isLinkValid(ctx: Context, linkType: string, linkAddress: string): {
16
26
  isValid: boolean;
@@ -1,8 +1,10 @@
1
1
  import _ from "lodash";
2
2
  import { getFlowdata } from "../context";
3
3
  import { getSheetIndex, isAllowEdit } from "../utils";
4
- import { mergeBorder } from "./cell";
4
+ import { cancelNormalSelected, mergeBorder } from "./cell";
5
+ import { setSelectionByCharacterOffset } from "./cursor";
5
6
  import { getcellrange, iscelldata } from "./formula";
7
+ import { applyLinkToSelection } from "./inline-string";
6
8
  import { colLocation, rowLocation } from "./location";
7
9
  import { normalizeSelection } from "./selection";
8
10
  import { changeSheet } from "./sheet";
@@ -38,9 +40,39 @@ export function getCellHyperlink(ctx, r, c) {
38
40
  }
39
41
  return undefined;
40
42
  }
41
- export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
43
+ export function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
44
+ var _a;
45
+ var applyToSelection = (options === null || options === void 0 ? void 0 : options.applyToSelection) && (options === null || options === void 0 ? void 0 : options.cellInput);
42
46
  var sheetIndex = getSheetIndex(ctx, ctx.currentSheetId);
43
47
  var flowdata = getFlowdata(ctx);
48
+ if (applyToSelection) {
49
+ if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
50
+ var cell = flowdata[r][c];
51
+ if (cell == null) cell = {};
52
+ _.set(ctx.luckysheetfile[sheetIndex], ["hyperlink", "".concat(r, "_").concat(c)], {
53
+ linkType: linkType,
54
+ linkAddress: linkAddress
55
+ });
56
+ cell.v = linkText || linkAddress;
57
+ cell.m = linkText || linkAddress;
58
+ cell.hl = {
59
+ r: r,
60
+ c: c,
61
+ id: ctx.currentSheetId
62
+ };
63
+ flowdata[r][c] = cell;
64
+ }
65
+ var offsets = (_a = ctx.linkCard) === null || _a === void 0 ? void 0 : _a.selectionOffsets;
66
+ if (offsets) {
67
+ setSelectionByCharacterOffset(options.cellInput, offsets.start, offsets.end);
68
+ }
69
+ applyLinkToSelection(options.cellInput, linkType, linkAddress);
70
+ ctx.linkCard = undefined;
71
+ return;
72
+ }
73
+ if (options === null || options === void 0 ? void 0 : options.cellInput) {
74
+ cancelNormalSelected(ctx);
75
+ }
44
76
  if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
45
77
  var cell = flowdata[r][c];
46
78
  if (cell == null) cell = {};
@@ -79,8 +111,8 @@ export function removeHyperlink(ctx, r, c) {
79
111
  }
80
112
  ctx.linkCard = undefined;
81
113
  }
82
- export function showLinkCard(ctx, r, c, isEditing, isMouseDown) {
83
- var _a, _b, _c, _d, _e, _f, _g;
114
+ export function showLinkCard(ctx, r, c, options, isEditing, isMouseDown) {
115
+ var _a, _b, _c, _d, _e, _f, _g, _h;
84
116
  if (isEditing === void 0) {
85
117
  isEditing = false;
86
118
  }
@@ -98,19 +130,26 @@ export function showLinkCard(ctx, r, c, isEditing, isMouseDown) {
98
130
  if (isEditing || link != null && (!((_f = ctx.linkCard) === null || _f === void 0 ? void 0 : _f.isEditing) || isMouseDown) || ((_g = ctx.linkCard) === null || _g === void 0 ? void 0 : _g.sheetId) !== ctx.currentSheetId) {
99
131
  var col_pre = c - 1 === -1 ? 0 : ctx.visibledatacolumn[c - 1];
100
132
  var row = ctx.visibledatarow[r];
133
+ var originText = function () {
134
+ if ((options === null || options === void 0 ? void 0 : options.originText) !== undefined) return options.originText;
135
+ if ((cell === null || cell === void 0 ? void 0 : cell.v) == null) return "";
136
+ return "".concat(cell.v);
137
+ }();
101
138
  ctx.linkCard = {
102
139
  sheetId: ctx.currentSheetId,
103
140
  r: r,
104
141
  c: c,
105
142
  rc: "".concat(r, "_").concat(c),
106
- originText: (cell === null || cell === void 0 ? void 0 : cell.v) == null ? "" : "".concat(cell.v),
143
+ originText: originText,
107
144
  originType: (link === null || link === void 0 ? void 0 : link.linkType) || "webpage",
108
145
  originAddress: (link === null || link === void 0 ? void 0 : link.linkAddress) || "",
109
146
  position: {
110
147
  cellLeft: col_pre,
111
148
  cellBottom: row
112
149
  },
113
- isEditing: isEditing
150
+ isEditing: isEditing,
151
+ applyToSelection: (_h = options === null || options === void 0 ? void 0 : options.applyToSelection) !== null && _h !== void 0 ? _h : false,
152
+ selectionOffsets: options === null || options === void 0 ? void 0 : options.selectionOffsets
114
153
  };
115
154
  }
116
155
  }
@@ -31,6 +31,14 @@ export declare function isInlineStringCell(cell: any): boolean;
31
31
  export declare function isInlineStringCT(ct: any): boolean;
32
32
  export declare function getInlineStringNoStyle(r: number, c: number, data: CellMatrix): string;
33
33
  export declare function convertCssToStyleList(cssText: string, originCell: Cell): CellStyle;
34
- export declare function convertSpanToShareString($dom: NodeListOf<HTMLSpanElement>, originCell: Cell): CellStyle[];
34
+ export type InlineSegmentLink = {
35
+ linkType: string;
36
+ linkAddress: string;
37
+ };
38
+ export declare function convertSpanToShareString($dom: NodeListOf<HTMLSpanElement>, originCell: Cell): (CellStyle & {
39
+ v?: string | undefined;
40
+ link?: InlineSegmentLink | undefined;
41
+ })[];
35
42
  export declare function updateInlineStringFormatOutside(cell: Cell, key: string, value: any): void;
36
43
  export declare function updateInlineStringFormat(ctx: Context, attr: keyof Cell, value: any, cellInput: HTMLDivElement): void;
44
+ export declare function applyLinkToSelection(cellInput: HTMLDivElement, linkType: string, linkAddress: string): void;
@@ -101,13 +101,20 @@ export function convertCssToStyleList(cssText, originCell) {
101
101
  return styleList;
102
102
  }
103
103
  export function convertSpanToShareString($dom, originCell) {
104
+ var _a, _b;
104
105
  var styles = [];
105
- var preStyleList;
106
+ var preStyleList = null;
106
107
  var preStyleListString = null;
107
108
  for (var i = 0; i < $dom.length; i += 1) {
108
109
  var span = $dom[i];
109
110
  var styleList = convertCssToStyleList(span.style.cssText, originCell);
110
- var curStyleListString = JSON.stringify(styleList);
111
+ if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
112
+ styleList.link = {
113
+ linkType: span.dataset.linkType,
114
+ linkAddress: span.dataset.linkAddress
115
+ };
116
+ }
117
+ var curStyleListString = JSON.stringify(_.omit(styleList, "link"));
111
118
  var v = span.innerText;
112
119
  v = v.replace(/\n/g, "\r\n");
113
120
  if (i === $dom.length - 1) {
@@ -115,7 +122,7 @@ export function convertSpanToShareString($dom, originCell) {
115
122
  v = v.slice(0, v.length - 2);
116
123
  }
117
124
  }
118
- if (curStyleListString === preStyleListString) {
125
+ if (curStyleListString === preStyleListString && _.isEqual(preStyleList === null || preStyleList === void 0 ? void 0 : preStyleList.link, styleList.link)) {
119
126
  preStyleList.v += v;
120
127
  } else {
121
128
  styleList.v = v;
@@ -434,4 +441,128 @@ export function updateInlineStringFormat(ctx, attr, value, cellInput) {
434
441
  }
435
442
  }
436
443
  }
444
+ }
445
+ function escapeHtmlAttr(s) {
446
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
447
+ }
448
+ function getLinkDataAttrs(span) {
449
+ var _a, _b;
450
+ if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
451
+ return " data-link-type='".concat(escapeHtmlAttr(span.dataset.linkType), "' data-link-address='").concat(escapeHtmlAttr(span.dataset.linkAddress), "'");
452
+ }
453
+ return "";
454
+ }
455
+ function getLinkStyleCssText(baseCssText) {
456
+ var css = getCssText(baseCssText, "fc", "rgb(0, 0, 255)");
457
+ css = getCssText(css, "un", 1);
458
+ return css;
459
+ }
460
+ export function applyLinkToSelection(cellInput, linkType, linkAddress) {
461
+ var _a, _b, _c;
462
+ var w = window.getSelection();
463
+ if (!w || w.rangeCount === 0) return;
464
+ var range = w.getRangeAt(0);
465
+ if (range.collapsed) return;
466
+ var $textEditor = cellInput;
467
+ var endContainer = range.endContainer,
468
+ startContainer = range.startContainer,
469
+ endOffset = range.endOffset,
470
+ startOffset = range.startOffset;
471
+ if (startContainer === endContainer) {
472
+ var span = startContainer.parentNode;
473
+ var content = (span === null || span === void 0 ? void 0 : span.innerHTML) || "";
474
+ var fullContent = $textEditor.innerHTML;
475
+ var inherit = fullContent.substring(0, 5) !== "<span";
476
+ var s2 = startOffset;
477
+ var s3 = endOffset;
478
+ var left = content.substring(0, s2);
479
+ var mid = content.substring(s2, s3);
480
+ var right = content.substring(s3, content.length);
481
+ var cont = "";
482
+ var dataAttrs = getLinkDataAttrs(span);
483
+ if (left !== "") {
484
+ var cssText = span.style.cssText;
485
+ if (inherit) {
486
+ var box = span.closest("#luckysheet-input-box");
487
+ if (box != null) cssText = extendCssText(box.style.cssText, cssText);
488
+ }
489
+ cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(left, "</span>");
490
+ }
491
+ if (mid !== "") {
492
+ var cssText = getLinkStyleCssText(span.style.cssText);
493
+ if (inherit) {
494
+ var box = span.closest("#luckysheet-input-box");
495
+ if (box != null) cssText = extendCssText(box.style.cssText, cssText);
496
+ }
497
+ cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(mid, "</span>");
498
+ }
499
+ if (right !== "") {
500
+ var cssText = span.style.cssText;
501
+ if (inherit) {
502
+ var box = span.closest("#luckysheet-input-box");
503
+ if (box != null) cssText = extendCssText(box.style.cssText, cssText);
504
+ }
505
+ cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(right, "</span>");
506
+ }
507
+ if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
508
+ span.outerHTML = cont;
509
+ } else {
510
+ span.innerHTML = cont;
511
+ }
512
+ var newSpans = $textEditor.querySelectorAll("span");
513
+ var linkSpanIndex = left === "" ? 0 : 1;
514
+ if (newSpans[linkSpanIndex]) {
515
+ selectTextContent(newSpans[linkSpanIndex]);
516
+ }
517
+ } else if (((_b = startContainer.parentElement) === null || _b === void 0 ? void 0 : _b.tagName) === "SPAN" && ((_c = endContainer.parentElement) === null || _c === void 0 ? void 0 : _c.tagName) === "SPAN") {
518
+ var startSpan = startContainer.parentNode;
519
+ var endSpan = endContainer.parentNode;
520
+ var allSpans = $textEditor.querySelectorAll("span");
521
+ var startSpanIndex = _.indexOf(allSpans, startSpan);
522
+ var endSpanIndex = _.indexOf(allSpans, endSpan);
523
+ var startContent = (startSpan === null || startSpan === void 0 ? void 0 : startSpan.innerHTML) || "";
524
+ var endContent = (endSpan === null || endSpan === void 0 ? void 0 : endSpan.innerHTML) || "";
525
+ var s2 = startOffset;
526
+ var s3 = endOffset;
527
+ var sleft = startContent.substring(0, s2);
528
+ var sright = startContent.substring(s2, startContent.length);
529
+ var eleft = endContent.substring(0, s3);
530
+ var eright = endContent.substring(s3, endContent.length);
531
+ var spans = $textEditor.querySelectorAll("span");
532
+ var cont = "";
533
+ for (var i = 0; i < startSpanIndex; i += 1) {
534
+ var sp = spans[i];
535
+ cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
536
+ }
537
+ if (sleft !== "") {
538
+ cont += "<span style='".concat(startSpan.style.cssText, "'").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
539
+ }
540
+ if (sright !== "") {
541
+ var cssText = getLinkStyleCssText(startSpan.style.cssText);
542
+ cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sright, "</span>");
543
+ }
544
+ if (startSpanIndex < endSpanIndex) {
545
+ for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
546
+ var sp = spans[i];
547
+ var cssText = getLinkStyleCssText(sp.style.cssText);
548
+ cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sp.innerHTML, "</span>");
549
+ }
550
+ }
551
+ if (eleft !== "") {
552
+ var cssText = getLinkStyleCssText(endSpan.style.cssText);
553
+ cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(eleft, "</span>");
554
+ }
555
+ if (eright !== "") {
556
+ cont += "<span style='".concat(endSpan.style.cssText, "'").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
557
+ }
558
+ for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
559
+ var sp = spans[i];
560
+ cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
561
+ }
562
+ $textEditor.innerHTML = cont;
563
+ spans = $textEditor.querySelectorAll("span");
564
+ var startSel = sleft === "" ? startSpanIndex : startSpanIndex + 1;
565
+ var endSel = eright === "" ? endSpanIndex : endSpanIndex + 1;
566
+ selectTextContentCross(spans[startSel], spans[endSel]);
567
+ }
437
568
  }
@@ -1613,6 +1613,7 @@ export function deleteSelectedCellFormat(ctx) {
1613
1613
  return "success";
1614
1614
  }
1615
1615
  export function fillRightData(ctx) {
1616
+ var _a, _b;
1616
1617
  var allowEdit = isAllowEdit(ctx);
1617
1618
  if (allowEdit === false) {
1618
1619
  return "allowEdit";
@@ -1640,10 +1641,20 @@ export function fillRightData(ctx) {
1640
1641
  var r2 = selection[s].row[1];
1641
1642
  var c1 = selection[s].column[0];
1642
1643
  var c2 = selection[s].column[1];
1643
- for (var r = r1; r <= r2; r += 1) {
1644
- for (var c = c1; c <= c2; c += 1) {
1645
- var previousCell = d[r][c - 1];
1646
- d[r][c] = __assign({}, previousCell);
1644
+ var isSingleCell = r1 === r2 && c1 === c2;
1645
+ if (isSingleCell) {
1646
+ if (c1 - 1 >= 0 && d[r1]) {
1647
+ var prev = d[r1][c1 - 1];
1648
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1649
+ }
1650
+ } else {
1651
+ for (var r = r1; r <= r2; r += 1) {
1652
+ var sourceCell = (_a = d[r]) === null || _a === void 0 ? void 0 : _a[c1];
1653
+ for (var c = c1 + 1; c <= c2; c += 1) {
1654
+ if (d[r]) {
1655
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
1656
+ }
1657
+ }
1647
1658
  }
1648
1659
  }
1649
1660
  }
@@ -1651,6 +1662,7 @@ export function fillRightData(ctx) {
1651
1662
  return "success";
1652
1663
  }
1653
1664
  export function fillDownData(ctx) {
1665
+ var _a, _b;
1654
1666
  var allowEdit = isAllowEdit(ctx);
1655
1667
  if (allowEdit === false) {
1656
1668
  return "allowEdit";
@@ -1678,10 +1690,20 @@ export function fillDownData(ctx) {
1678
1690
  var r2 = selection[s].row[1];
1679
1691
  var c1 = selection[s].column[0];
1680
1692
  var c2 = selection[s].column[1];
1681
- for (var r = r1; r <= r2; r += 1) {
1693
+ var isSingleCell = r1 === r2 && c1 === c2;
1694
+ if (isSingleCell) {
1695
+ if (r1 - 1 >= 0 && d[r1 - 1]) {
1696
+ var prev = d[r1 - 1][c1];
1697
+ if (!d[r1]) d[r1] = [];
1698
+ d[r1][c1] = prev != null ? __assign({}, prev) : {};
1699
+ }
1700
+ } else {
1682
1701
  for (var c = c1; c <= c2; c += 1) {
1683
- var previousCell = d[r - 1][c];
1684
- d[r][c] = __assign({}, previousCell);
1702
+ var sourceCell = (_a = d[r1]) === null || _a === void 0 ? void 0 : _a[c];
1703
+ for (var r = r1 + 1; r <= r2; r += 1) {
1704
+ if (!d[r]) d[r] = [];
1705
+ d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
1706
+ }
1685
1707
  }
1686
1708
  }
1687
1709
  }
@@ -26,7 +26,7 @@ export declare function handleSort(ctx: Context, isAsc: boolean): void;
26
26
  export declare function handleFreeze(ctx: Context, type: string): void;
27
27
  export declare function handleTextSize(ctx: Context, cellInput: HTMLDivElement, size: number, canvas?: CanvasRenderingContext2D): void;
28
28
  export declare function handleSum(ctx: Context, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, cache?: GlobalCache): void;
29
- export declare function handleLink(ctx: Context): void;
29
+ export declare function handleLink(ctx: Context, cellInput: HTMLDivElement | null | undefined): void;
30
30
  export declare function toolbarItemClickHandler(name: string): ToolbarItemClickHandler;
31
31
  export declare function toolbarItemSelectedFunc(name: string): ToolbarItemSelectedFunc;
32
32
  export {};
@@ -5,6 +5,7 @@ import { getSheetIndex, isAllowEdit, getLineCount } from "../utils";
5
5
  import { getRangetxt, isAllSelectedCellsInStatus, normalizedAttr, setCellValue } from "./cell";
6
6
  import { colors } from "./color";
7
7
  import { genarate, is_date, update } from "./format";
8
+ import { getSelectionCharacterOffsets } from "./cursor";
8
9
  import { execfunction, execFunctionGroup, israngeseleciton, rangeSetValue, setCaretPosition, createFormulaRangeSelect } from "./formula";
9
10
  import { inlineStyleAffectAttribute, updateInlineStringFormat, updateInlineStringFormatOutside } from "./inline-string";
10
11
  import { colLocationByIndex, rowLocationByIndex } from "./location";
@@ -969,15 +970,36 @@ export function handleTextSize(ctx, cellInput, size, canvas) {
969
970
  export function handleSum(ctx, cellInput, fxInput, cache) {
970
971
  autoSelectionFormula(ctx, cellInput, fxInput, "SUM", cache);
971
972
  }
972
- export function handleLink(ctx) {
973
- var _a;
973
+ export function handleLink(ctx, cellInput) {
974
+ var _a, _b, _c;
974
975
  var allowEdit = isAllowEdit(ctx);
975
976
  if (!allowEdit) return;
976
977
  var selection = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
977
978
  var flowdata = getFlowdata(ctx);
978
- if (flowdata != null && selection != null) {
979
- showLinkCard(ctx, selection.row[0], selection.column[0], true);
979
+ if (flowdata == null || selection == null) return;
980
+ var r = selection.row[0];
981
+ var c = selection.column[0];
982
+ var isEditMode = ((_b = ctx.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length) === 2 && ctx.luckysheetCellUpdate[0] === r && ctx.luckysheetCellUpdate[1] === c;
983
+ var applyToSelection = false;
984
+ var originText;
985
+ var selectionOffsets;
986
+ if (isEditMode && cellInput) {
987
+ var sel = window.getSelection();
988
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed && cellInput.contains(sel.anchorNode)) {
989
+ var value = (_c = cellInput.innerText) !== null && _c !== void 0 ? _c : "";
990
+ if (value.substring(0, 1) !== "=") {
991
+ originText = sel.toString();
992
+ applyToSelection = true;
993
+ var off = getSelectionCharacterOffsets(cellInput);
994
+ if (off) selectionOffsets = off;
995
+ }
996
+ }
980
997
  }
998
+ showLinkCard(ctx, r, c, {
999
+ applyToSelection: applyToSelection || undefined,
1000
+ originText: originText,
1001
+ selectionOffsets: selectionOffsets
1002
+ }, true, false);
981
1003
  }
982
1004
  var handlerMap = {
983
1005
  "currency-format": handleCurrencyFormat,
package/es/types.d.ts CHANGED
@@ -269,6 +269,11 @@ export type LinkCardProps = {
269
269
  };
270
270
  isEditing: boolean;
271
271
  selectingCellRange?: boolean;
272
+ applyToSelection?: boolean;
273
+ selectionOffsets?: {
274
+ start: number;
275
+ end: number;
276
+ };
272
277
  };
273
278
  export type RangeDialogProps = {
274
279
  show: boolean;