@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 +37 -1
- package/es/events/keyboard.js +4 -4
- package/es/events/mouse.js +1 -1
- package/es/events/paste.js +4 -5
- package/es/modules/cell.js +7 -1
- package/es/modules/cursor.d.ts +5 -0
- package/es/modules/cursor.js +55 -0
- package/es/modules/hyperlink.d.ts +12 -2
- package/es/modules/hyperlink.js +45 -6
- package/es/modules/inline-string.d.ts +9 -1
- package/es/modules/inline-string.js +134 -3
- package/es/modules/selection.js +29 -7
- package/es/modules/toolbar.d.ts +1 -1
- package/es/modules/toolbar.js +26 -4
- package/es/types.d.ts +5 -0
- package/lib/api/sheet.js +37 -1
- package/lib/events/keyboard.js +4 -4
- package/lib/events/mouse.js +1 -1
- package/lib/events/paste.js +4 -5
- package/lib/modules/cell.js +7 -1
- package/lib/modules/cursor.d.ts +5 -0
- package/lib/modules/cursor.js +57 -0
- package/lib/modules/hyperlink.d.ts +12 -2
- package/lib/modules/hyperlink.js +44 -5
- package/lib/modules/inline-string.d.ts +9 -1
- package/lib/modules/inline-string.js +135 -3
- package/lib/modules/selection.js +29 -7
- package/lib/modules/toolbar.d.ts +1 -1
- package/lib/modules/toolbar.js +26 -4
- package/lib/types.d.ts +5 -0
- package/package.json +1 -1
package/lib/api/sheet.js
CHANGED
|
@@ -22,6 +22,17 @@ var _common = require("./common");
|
|
|
22
22
|
var _utils = require("../utils");
|
|
23
23
|
var _2 = require("..");
|
|
24
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
25
|
+
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); }
|
|
26
|
+
var __assign = void 0 && (void 0).__assign || function () {
|
|
27
|
+
__assign = Object.assign || function (t) {
|
|
28
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
+
s = arguments[i];
|
|
30
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
};
|
|
34
|
+
return __assign.apply(this, arguments);
|
|
35
|
+
};
|
|
25
36
|
function isCellReferenced(formulaString, cell) {
|
|
26
37
|
function colToNumber(col) {
|
|
27
38
|
var num = 0;
|
|
@@ -153,6 +164,7 @@ function generateCopySheetName(ctx, sheetId) {
|
|
|
153
164
|
return sheetCopyName;
|
|
154
165
|
}
|
|
155
166
|
function copySheet(ctx, sheetId) {
|
|
167
|
+
var _a, _b, _c;
|
|
156
168
|
var index = (0, _utils.getSheetIndex)(ctx, sheetId);
|
|
157
169
|
var order = ctx.luckysheetfile[index].order + 1;
|
|
158
170
|
var sheetName = generateCopySheetName(ctx, sheetId);
|
|
@@ -162,8 +174,32 @@ function copySheet(ctx, sheetId) {
|
|
|
162
174
|
sheetData.celldata = (0, _common.dataToCelldata)(sheetData.data);
|
|
163
175
|
delete sheetData.data;
|
|
164
176
|
_2.api.addSheet(ctx, undefined, (0, _uuid.v4)(), ctx.luckysheetfile[index].isPivotTable, sheetName, sheetData);
|
|
177
|
+
var newSheetIndex = ctx.luckysheetfile.length - 1;
|
|
178
|
+
var newSheet = ctx.luckysheetfile[newSheetIndex];
|
|
179
|
+
var newSheetId = newSheet.id;
|
|
180
|
+
if ((_a = newSheet.calcChain) === null || _a === void 0 ? void 0 : _a.length) {
|
|
181
|
+
newSheet.calcChain = newSheet.calcChain.map(function (entry) {
|
|
182
|
+
return __assign(__assign({}, entry), {
|
|
183
|
+
id: newSheetId
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if ((_b = newSheet.dynamicArray) === null || _b === void 0 ? void 0 : _b.length) {
|
|
188
|
+
newSheet.dynamicArray = newSheet.dynamicArray.map(function (entry) {
|
|
189
|
+
return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
|
|
190
|
+
id: newSheetId
|
|
191
|
+
}) : entry;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if ((_c = newSheet.dynamicArray_compute) === null || _c === void 0 ? void 0 : _c.length) {
|
|
195
|
+
newSheet.dynamicArray_compute = newSheet.dynamicArray_compute.map(function (entry) {
|
|
196
|
+
return entry && _typeof(entry) === "object" && "id" in entry ? __assign(__assign({}, entry), {
|
|
197
|
+
id: newSheetId
|
|
198
|
+
}) : entry;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
165
201
|
var sheetOrderList = {};
|
|
166
|
-
sheetOrderList[
|
|
202
|
+
sheetOrderList[newSheetId] = order;
|
|
167
203
|
_2.api.setSheetOrder(ctx, sheetOrderList);
|
|
168
204
|
}
|
|
169
205
|
function calculateSheetFromula(ctx, id) {
|
package/lib/events/keyboard.js
CHANGED
|
@@ -149,7 +149,7 @@ function handleGlobalEnter(ctx, cellInput, e, canvas) {
|
|
|
149
149
|
row_focus: lastCellUpdate[0],
|
|
150
150
|
column_focus: lastCellUpdate[1]
|
|
151
151
|
}];
|
|
152
|
-
(0, _selection.moveHighlightCell)(ctx, "down",
|
|
152
|
+
(0, _selection.moveHighlightCell)(ctx, "down", (0, _2.hideCRCount)(ctx, "ArrowDown"), "rangeOfSelect");
|
|
153
153
|
e.preventDefault();
|
|
154
154
|
} else {
|
|
155
155
|
if (((_c = (_b = ctx.luckysheet_select_save) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0) {
|
|
@@ -406,7 +406,7 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
|
|
|
406
406
|
(0, _selection.textFormat)(ctx, "right");
|
|
407
407
|
}
|
|
408
408
|
if ((e.metaKey || e.ctrlKey) && e.code === "KeyK") {
|
|
409
|
-
(0, _toolbar.handleLink)(ctx);
|
|
409
|
+
(0, _toolbar.handleLink)(ctx, cellInput);
|
|
410
410
|
}
|
|
411
411
|
if ((e.metaKey || e.ctrlKey) && !e.shiftKey && e.code === "Semicolon") {
|
|
412
412
|
(0, _selection.fillDate)(ctx);
|
|
@@ -444,9 +444,9 @@ function handleGlobalKeyDown(ctx, cellInput, fxInput, e, cache, handleUndo, hand
|
|
|
444
444
|
(0, _cell.updateCell)(ctx, ctx.luckysheetCellUpdate[0], ctx.luckysheetCellUpdate[1], cellInput, undefined, canvas);
|
|
445
445
|
}
|
|
446
446
|
if (e.shiftKey) {
|
|
447
|
-
(0, _selection.moveHighlightCell)(ctx, "right", -
|
|
447
|
+
(0, _selection.moveHighlightCell)(ctx, "right", -(0, _2.hideCRCount)(ctx, "ArrowLeft"), "rangeOfSelect");
|
|
448
448
|
} else {
|
|
449
|
-
(0, _selection.moveHighlightCell)(ctx, "right",
|
|
449
|
+
(0, _selection.moveHighlightCell)(ctx, "right", (0, _2.hideCRCount)(ctx, "ArrowRight"), "rangeOfSelect");
|
|
450
450
|
}
|
|
451
451
|
e.preventDefault();
|
|
452
452
|
} else if (kstr === "F2") {
|
package/lib/events/mouse.js
CHANGED
|
@@ -166,7 +166,7 @@ function handleCellAreaMouseDown(ctx, globalCache, e, cellInput, container, fxIn
|
|
|
166
166
|
_a = margeset.row, row_pre = _a[0], row = _a[1], row_index = _a[2], row_index_ed = _a[3];
|
|
167
167
|
_b = margeset.column, col_pre = _b[0], col = _b[1], col_index = _b[2], col_index_ed = _b[3];
|
|
168
168
|
}
|
|
169
|
-
(0, _hyperlink.showLinkCard)(ctx, row_index, col_index, false, true);
|
|
169
|
+
(0, _hyperlink.showLinkCard)(ctx, row_index, col_index, undefined, false, true);
|
|
170
170
|
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], {
|
|
171
171
|
row: row_index,
|
|
172
172
|
column: col_index,
|
package/lib/events/paste.js
CHANGED
|
@@ -91,11 +91,9 @@ function adjustFormulaForPaste(formula, srcCol, srcRow, destCol, destRow) {
|
|
|
91
91
|
var rowOffset = destRow - srcRow;
|
|
92
92
|
var hadInvalid = false;
|
|
93
93
|
var cellRefRegex = /\b(\$?)([A-Z]+)(\$?)(\d+)\b/g;
|
|
94
|
-
var stringOrCellRef = /"(?:\\.|[^"])*"|(
|
|
94
|
+
var stringOrCellRef = /"(?:\\.|[^"])*"|(\$?[A-Z]+\$?\d+)(?!\s*!)\b/g;
|
|
95
95
|
var result = formula.replace(stringOrCellRef, function (m, cellRef) {
|
|
96
96
|
if (!cellRef) return m;
|
|
97
|
-
if (cellRef.startsWith("$")) return m;
|
|
98
|
-
console.log(m, "cellRef", cellRef);
|
|
99
97
|
return cellRef.replace(cellRefRegex, function (__, absCol, colLetters, absRow, rowNum) {
|
|
100
98
|
var colIndex = columnLabelIndex(colLetters);
|
|
101
99
|
var rowIndex = parseInt(rowNum, 10);
|
|
@@ -1024,9 +1022,10 @@ function pasteHandlerOfCopyPaste(ctx, copyRange) {
|
|
|
1024
1022
|
if (!_lodash.default.isNil(value) && !_lodash.default.isNil(value.f)) {
|
|
1025
1023
|
var adjustedFormula = value.f;
|
|
1026
1024
|
var isError = false;
|
|
1025
|
+
var srcRow = c_r1 + (h - mth);
|
|
1026
|
+
var srcCol = c_c1 + (c - mtc);
|
|
1027
1027
|
try {
|
|
1028
|
-
adjustedFormula = adjustFormulaForPaste(value.f,
|
|
1029
|
-
console.log("adjustedFormula", adjustedFormula);
|
|
1028
|
+
adjustedFormula = adjustFormulaForPaste(value.f, srcCol, srcRow, c, h);
|
|
1030
1029
|
} catch (error) {
|
|
1031
1030
|
isError = true;
|
|
1032
1031
|
value.error = {
|
package/lib/modules/cell.js
CHANGED
|
@@ -1155,10 +1155,16 @@ function getInlineStringHTML(r, c, data) {
|
|
|
1155
1155
|
var strObj = strings[i];
|
|
1156
1156
|
if (strObj.v) {
|
|
1157
1157
|
var style = getFontStyleByCell(strObj);
|
|
1158
|
+
var link = strObj.link;
|
|
1159
|
+
if ((link === null || link === void 0 ? void 0 : link.linkType) && (link === null || link === void 0 ? void 0 : link.linkAddress)) {
|
|
1160
|
+
style.color = style.color || "rgb(0, 0, 255)";
|
|
1161
|
+
style.borderBottom = style.borderBottom || "1px solid rgb(0, 0, 255)";
|
|
1162
|
+
}
|
|
1158
1163
|
var styleStr = _lodash.default.map(style, function (v, key) {
|
|
1159
1164
|
return "".concat(_lodash.default.kebabCase(key), ":").concat(_lodash.default.isNumber(v) ? "".concat(v, "px") : v, ";");
|
|
1160
1165
|
}).join("");
|
|
1161
|
-
|
|
1166
|
+
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, "'"), "' data-link-address='").concat(String(link.linkAddress).replace(/'/g, "'"), "'") : "";
|
|
1167
|
+
value += "<span class=\"luckysheet-input-span\" index='".concat(i, "' style='").concat(styleStr, "'").concat(dataAttrs, ">").concat(strObj.v, "</span>");
|
|
1162
1168
|
}
|
|
1163
1169
|
}
|
|
1164
1170
|
return value;
|
package/lib/modules/cursor.d.ts
CHANGED
|
@@ -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;
|
package/lib/modules/cursor.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getSelectionCharacterOffsets = getSelectionCharacterOffsets;
|
|
6
7
|
exports.moveToEnd = moveToEnd;
|
|
7
8
|
exports.selectTextContent = selectTextContent;
|
|
8
9
|
exports.selectTextContentCross = selectTextContentCross;
|
|
10
|
+
exports.setSelectionByCharacterOffset = setSelectionByCharacterOffset;
|
|
9
11
|
function moveToEnd(obj) {
|
|
10
12
|
if (document.createRange) {
|
|
11
13
|
if (obj.innerHTML !== obj.innerText || obj.innerHTML === "") {
|
|
@@ -67,4 +69,59 @@ function selectTextContentCross(sEle, eEle) {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
72
|
+
}
|
|
73
|
+
function getSelectionCharacterOffsets(element) {
|
|
74
|
+
var sel = window.getSelection();
|
|
75
|
+
if (!sel || sel.rangeCount === 0) return null;
|
|
76
|
+
var range = sel.getRangeAt(0);
|
|
77
|
+
if (range.collapsed) return null;
|
|
78
|
+
if (!element.contains(range.startContainer) || !element.contains(range.endContainer)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
var pre = document.createRange();
|
|
82
|
+
pre.selectNodeContents(element);
|
|
83
|
+
pre.setEnd(range.startContainer, range.startOffset);
|
|
84
|
+
var start = pre.toString().length;
|
|
85
|
+
return {
|
|
86
|
+
start: start,
|
|
87
|
+
end: start + range.toString().length
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function setSelectionByCharacterOffset(element, start, end) {
|
|
91
|
+
element.focus();
|
|
92
|
+
var sel = window.getSelection();
|
|
93
|
+
if (!sel) return;
|
|
94
|
+
var charIndex = 0;
|
|
95
|
+
var startNode = null;
|
|
96
|
+
var startOffset = 0;
|
|
97
|
+
var endNode = null;
|
|
98
|
+
var endOffset = 0;
|
|
99
|
+
function walk(node) {
|
|
100
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
101
|
+
var len = (node.textContent || "").length;
|
|
102
|
+
if (startNode == null && charIndex + len > start) {
|
|
103
|
+
startNode = node;
|
|
104
|
+
startOffset = start - charIndex;
|
|
105
|
+
}
|
|
106
|
+
if (endNode == null && charIndex + len >= end) {
|
|
107
|
+
endNode = node;
|
|
108
|
+
endOffset = end - charIndex;
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
charIndex += len;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
for (var i = 0; i < node.childNodes.length; i += 1) {
|
|
115
|
+
if (walk(node.childNodes[i])) return true;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
walk(element);
|
|
120
|
+
if (startNode && endNode) {
|
|
121
|
+
var range = document.createRange();
|
|
122
|
+
range.setStart(startNode, startOffset);
|
|
123
|
+
range.setEnd(endNode, endOffset);
|
|
124
|
+
sel.removeAllRanges();
|
|
125
|
+
sel.addRange(range);
|
|
126
|
+
}
|
|
70
127
|
}
|
|
@@ -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
|
|
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,
|
|
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;
|
package/lib/modules/hyperlink.js
CHANGED
|
@@ -17,7 +17,9 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
17
17
|
var _context = require("../context");
|
|
18
18
|
var _utils = require("../utils");
|
|
19
19
|
var _cell = require("./cell");
|
|
20
|
+
var _cursor = require("./cursor");
|
|
20
21
|
var _formula = require("./formula");
|
|
22
|
+
var _inlineString = require("./inline-string");
|
|
21
23
|
var _location = require("./location");
|
|
22
24
|
var _selection = require("./selection");
|
|
23
25
|
var _sheet = require("./sheet");
|
|
@@ -54,9 +56,39 @@ function getCellHyperlink(ctx, r, c) {
|
|
|
54
56
|
}
|
|
55
57
|
return undefined;
|
|
56
58
|
}
|
|
57
|
-
function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress) {
|
|
59
|
+
function saveHyperlink(ctx, r, c, linkText, linkType, linkAddress, options) {
|
|
60
|
+
var _a;
|
|
61
|
+
var applyToSelection = (options === null || options === void 0 ? void 0 : options.applyToSelection) && (options === null || options === void 0 ? void 0 : options.cellInput);
|
|
58
62
|
var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
59
63
|
var flowdata = (0, _context.getFlowdata)(ctx);
|
|
64
|
+
if (applyToSelection) {
|
|
65
|
+
if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
|
|
66
|
+
var cell = flowdata[r][c];
|
|
67
|
+
if (cell == null) cell = {};
|
|
68
|
+
_lodash.default.set(ctx.luckysheetfile[sheetIndex], ["hyperlink", "".concat(r, "_").concat(c)], {
|
|
69
|
+
linkType: linkType,
|
|
70
|
+
linkAddress: linkAddress
|
|
71
|
+
});
|
|
72
|
+
cell.v = linkText || linkAddress;
|
|
73
|
+
cell.m = linkText || linkAddress;
|
|
74
|
+
cell.hl = {
|
|
75
|
+
r: r,
|
|
76
|
+
c: c,
|
|
77
|
+
id: ctx.currentSheetId
|
|
78
|
+
};
|
|
79
|
+
flowdata[r][c] = cell;
|
|
80
|
+
}
|
|
81
|
+
var offsets = (_a = ctx.linkCard) === null || _a === void 0 ? void 0 : _a.selectionOffsets;
|
|
82
|
+
if (offsets) {
|
|
83
|
+
(0, _cursor.setSelectionByCharacterOffset)(options.cellInput, offsets.start, offsets.end);
|
|
84
|
+
}
|
|
85
|
+
(0, _inlineString.applyLinkToSelection)(options.cellInput, linkType, linkAddress);
|
|
86
|
+
ctx.linkCard = undefined;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (options === null || options === void 0 ? void 0 : options.cellInput) {
|
|
90
|
+
(0, _cell.cancelNormalSelected)(ctx);
|
|
91
|
+
}
|
|
60
92
|
if (sheetIndex != null && flowdata != null && linkType && linkAddress) {
|
|
61
93
|
var cell = flowdata[r][c];
|
|
62
94
|
if (cell == null) cell = {};
|
|
@@ -95,8 +127,8 @@ function removeHyperlink(ctx, r, c) {
|
|
|
95
127
|
}
|
|
96
128
|
ctx.linkCard = undefined;
|
|
97
129
|
}
|
|
98
|
-
function showLinkCard(ctx, r, c, isEditing, isMouseDown) {
|
|
99
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
130
|
+
function showLinkCard(ctx, r, c, options, isEditing, isMouseDown) {
|
|
131
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
100
132
|
if (isEditing === void 0) {
|
|
101
133
|
isEditing = false;
|
|
102
134
|
}
|
|
@@ -114,19 +146,26 @@ function showLinkCard(ctx, r, c, isEditing, isMouseDown) {
|
|
|
114
146
|
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) {
|
|
115
147
|
var col_pre = c - 1 === -1 ? 0 : ctx.visibledatacolumn[c - 1];
|
|
116
148
|
var row = ctx.visibledatarow[r];
|
|
149
|
+
var originText = function () {
|
|
150
|
+
if ((options === null || options === void 0 ? void 0 : options.originText) !== undefined) return options.originText;
|
|
151
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.v) == null) return "";
|
|
152
|
+
return "".concat(cell.v);
|
|
153
|
+
}();
|
|
117
154
|
ctx.linkCard = {
|
|
118
155
|
sheetId: ctx.currentSheetId,
|
|
119
156
|
r: r,
|
|
120
157
|
c: c,
|
|
121
158
|
rc: "".concat(r, "_").concat(c),
|
|
122
|
-
originText:
|
|
159
|
+
originText: originText,
|
|
123
160
|
originType: (link === null || link === void 0 ? void 0 : link.linkType) || "webpage",
|
|
124
161
|
originAddress: (link === null || link === void 0 ? void 0 : link.linkAddress) || "",
|
|
125
162
|
position: {
|
|
126
163
|
cellLeft: col_pre,
|
|
127
164
|
cellBottom: row
|
|
128
165
|
},
|
|
129
|
-
isEditing: isEditing
|
|
166
|
+
isEditing: isEditing,
|
|
167
|
+
applyToSelection: (_h = options === null || options === void 0 ? void 0 : options.applyToSelection) !== null && _h !== void 0 ? _h : false,
|
|
168
|
+
selectionOffsets: options === null || options === void 0 ? void 0 : options.selectionOffsets
|
|
130
169
|
};
|
|
131
170
|
}
|
|
132
171
|
}
|
|
@@ -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
|
|
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;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.applyLinkToSelection = applyLinkToSelection;
|
|
6
7
|
exports.attrToCssName = void 0;
|
|
7
8
|
exports.convertCssToStyleList = convertCssToStyleList;
|
|
8
9
|
exports.convertSpanToShareString = convertSpanToShareString;
|
|
@@ -116,13 +117,20 @@ function convertCssToStyleList(cssText, originCell) {
|
|
|
116
117
|
return styleList;
|
|
117
118
|
}
|
|
118
119
|
function convertSpanToShareString($dom, originCell) {
|
|
120
|
+
var _a, _b;
|
|
119
121
|
var styles = [];
|
|
120
|
-
var preStyleList;
|
|
122
|
+
var preStyleList = null;
|
|
121
123
|
var preStyleListString = null;
|
|
122
124
|
for (var i = 0; i < $dom.length; i += 1) {
|
|
123
125
|
var span = $dom[i];
|
|
124
126
|
var styleList = convertCssToStyleList(span.style.cssText, originCell);
|
|
125
|
-
|
|
127
|
+
if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
|
|
128
|
+
styleList.link = {
|
|
129
|
+
linkType: span.dataset.linkType,
|
|
130
|
+
linkAddress: span.dataset.linkAddress
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
var curStyleListString = JSON.stringify(_lodash.default.omit(styleList, "link"));
|
|
126
134
|
var v = span.innerText;
|
|
127
135
|
v = v.replace(/\n/g, "\r\n");
|
|
128
136
|
if (i === $dom.length - 1) {
|
|
@@ -130,7 +138,7 @@ function convertSpanToShareString($dom, originCell) {
|
|
|
130
138
|
v = v.slice(0, v.length - 2);
|
|
131
139
|
}
|
|
132
140
|
}
|
|
133
|
-
if (curStyleListString === preStyleListString) {
|
|
141
|
+
if (curStyleListString === preStyleListString && _lodash.default.isEqual(preStyleList === null || preStyleList === void 0 ? void 0 : preStyleList.link, styleList.link)) {
|
|
134
142
|
preStyleList.v += v;
|
|
135
143
|
} else {
|
|
136
144
|
styleList.v = v;
|
|
@@ -449,4 +457,128 @@ function updateInlineStringFormat(ctx, attr, value, cellInput) {
|
|
|
449
457
|
}
|
|
450
458
|
}
|
|
451
459
|
}
|
|
460
|
+
}
|
|
461
|
+
function escapeHtmlAttr(s) {
|
|
462
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
463
|
+
}
|
|
464
|
+
function getLinkDataAttrs(span) {
|
|
465
|
+
var _a, _b;
|
|
466
|
+
if (((_a = span.dataset) === null || _a === void 0 ? void 0 : _a.linkType) && ((_b = span.dataset) === null || _b === void 0 ? void 0 : _b.linkAddress)) {
|
|
467
|
+
return " data-link-type='".concat(escapeHtmlAttr(span.dataset.linkType), "' data-link-address='").concat(escapeHtmlAttr(span.dataset.linkAddress), "'");
|
|
468
|
+
}
|
|
469
|
+
return "";
|
|
470
|
+
}
|
|
471
|
+
function getLinkStyleCssText(baseCssText) {
|
|
472
|
+
var css = getCssText(baseCssText, "fc", "rgb(0, 0, 255)");
|
|
473
|
+
css = getCssText(css, "un", 1);
|
|
474
|
+
return css;
|
|
475
|
+
}
|
|
476
|
+
function applyLinkToSelection(cellInput, linkType, linkAddress) {
|
|
477
|
+
var _a, _b, _c;
|
|
478
|
+
var w = window.getSelection();
|
|
479
|
+
if (!w || w.rangeCount === 0) return;
|
|
480
|
+
var range = w.getRangeAt(0);
|
|
481
|
+
if (range.collapsed) return;
|
|
482
|
+
var $textEditor = cellInput;
|
|
483
|
+
var endContainer = range.endContainer,
|
|
484
|
+
startContainer = range.startContainer,
|
|
485
|
+
endOffset = range.endOffset,
|
|
486
|
+
startOffset = range.startOffset;
|
|
487
|
+
if (startContainer === endContainer) {
|
|
488
|
+
var span = startContainer.parentNode;
|
|
489
|
+
var content = (span === null || span === void 0 ? void 0 : span.innerHTML) || "";
|
|
490
|
+
var fullContent = $textEditor.innerHTML;
|
|
491
|
+
var inherit = fullContent.substring(0, 5) !== "<span";
|
|
492
|
+
var s2 = startOffset;
|
|
493
|
+
var s3 = endOffset;
|
|
494
|
+
var left = content.substring(0, s2);
|
|
495
|
+
var mid = content.substring(s2, s3);
|
|
496
|
+
var right = content.substring(s3, content.length);
|
|
497
|
+
var cont = "";
|
|
498
|
+
var dataAttrs = getLinkDataAttrs(span);
|
|
499
|
+
if (left !== "") {
|
|
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(left, "</span>");
|
|
506
|
+
}
|
|
507
|
+
if (mid !== "") {
|
|
508
|
+
var cssText = getLinkStyleCssText(span.style.cssText);
|
|
509
|
+
if (inherit) {
|
|
510
|
+
var box = span.closest("#luckysheet-input-box");
|
|
511
|
+
if (box != null) cssText = extendCssText(box.style.cssText, cssText);
|
|
512
|
+
}
|
|
513
|
+
cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(mid, "</span>");
|
|
514
|
+
}
|
|
515
|
+
if (right !== "") {
|
|
516
|
+
var cssText = span.style.cssText;
|
|
517
|
+
if (inherit) {
|
|
518
|
+
var box = span.closest("#luckysheet-input-box");
|
|
519
|
+
if (box != null) cssText = extendCssText(box.style.cssText, cssText);
|
|
520
|
+
}
|
|
521
|
+
cont += "<span style='".concat(cssText, "'").concat(dataAttrs, ">").concat(right, "</span>");
|
|
522
|
+
}
|
|
523
|
+
if (((_a = startContainer.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === "SPAN") {
|
|
524
|
+
span.outerHTML = cont;
|
|
525
|
+
} else {
|
|
526
|
+
span.innerHTML = cont;
|
|
527
|
+
}
|
|
528
|
+
var newSpans = $textEditor.querySelectorAll("span");
|
|
529
|
+
var linkSpanIndex = left === "" ? 0 : 1;
|
|
530
|
+
if (newSpans[linkSpanIndex]) {
|
|
531
|
+
(0, _cursor.selectTextContent)(newSpans[linkSpanIndex]);
|
|
532
|
+
}
|
|
533
|
+
} 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") {
|
|
534
|
+
var startSpan = startContainer.parentNode;
|
|
535
|
+
var endSpan = endContainer.parentNode;
|
|
536
|
+
var allSpans = $textEditor.querySelectorAll("span");
|
|
537
|
+
var startSpanIndex = _lodash.default.indexOf(allSpans, startSpan);
|
|
538
|
+
var endSpanIndex = _lodash.default.indexOf(allSpans, endSpan);
|
|
539
|
+
var startContent = (startSpan === null || startSpan === void 0 ? void 0 : startSpan.innerHTML) || "";
|
|
540
|
+
var endContent = (endSpan === null || endSpan === void 0 ? void 0 : endSpan.innerHTML) || "";
|
|
541
|
+
var s2 = startOffset;
|
|
542
|
+
var s3 = endOffset;
|
|
543
|
+
var sleft = startContent.substring(0, s2);
|
|
544
|
+
var sright = startContent.substring(s2, startContent.length);
|
|
545
|
+
var eleft = endContent.substring(0, s3);
|
|
546
|
+
var eright = endContent.substring(s3, endContent.length);
|
|
547
|
+
var spans = $textEditor.querySelectorAll("span");
|
|
548
|
+
var cont = "";
|
|
549
|
+
for (var i = 0; i < startSpanIndex; i += 1) {
|
|
550
|
+
var sp = spans[i];
|
|
551
|
+
cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
|
|
552
|
+
}
|
|
553
|
+
if (sleft !== "") {
|
|
554
|
+
cont += "<span style='".concat(startSpan.style.cssText, "'").concat(getLinkDataAttrs(startSpan), ">").concat(sleft, "</span>");
|
|
555
|
+
}
|
|
556
|
+
if (sright !== "") {
|
|
557
|
+
var cssText = getLinkStyleCssText(startSpan.style.cssText);
|
|
558
|
+
cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sright, "</span>");
|
|
559
|
+
}
|
|
560
|
+
if (startSpanIndex < endSpanIndex) {
|
|
561
|
+
for (var i = startSpanIndex + 1; i < endSpanIndex; i += 1) {
|
|
562
|
+
var sp = spans[i];
|
|
563
|
+
var cssText = getLinkStyleCssText(sp.style.cssText);
|
|
564
|
+
cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(sp.innerHTML, "</span>");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (eleft !== "") {
|
|
568
|
+
var cssText = getLinkStyleCssText(endSpan.style.cssText);
|
|
569
|
+
cont += "<span style='".concat(cssText, "' data-link-type='").concat(escapeHtmlAttr(linkType), "' data-link-address='").concat(escapeHtmlAttr(linkAddress), "'>").concat(eleft, "</span>");
|
|
570
|
+
}
|
|
571
|
+
if (eright !== "") {
|
|
572
|
+
cont += "<span style='".concat(endSpan.style.cssText, "'").concat(getLinkDataAttrs(endSpan), ">").concat(eright, "</span>");
|
|
573
|
+
}
|
|
574
|
+
for (var i = endSpanIndex + 1; i < spans.length; i += 1) {
|
|
575
|
+
var sp = spans[i];
|
|
576
|
+
cont += "<span style='".concat(sp.style.cssText, "'").concat(getLinkDataAttrs(sp), ">").concat(sp.innerHTML, "</span>");
|
|
577
|
+
}
|
|
578
|
+
$textEditor.innerHTML = cont;
|
|
579
|
+
spans = $textEditor.querySelectorAll("span");
|
|
580
|
+
var startSel = sleft === "" ? startSpanIndex : startSpanIndex + 1;
|
|
581
|
+
var endSel = eright === "" ? endSpanIndex : endSpanIndex + 1;
|
|
582
|
+
(0, _cursor.selectTextContentCross)(spans[startSel], spans[endSel]);
|
|
583
|
+
}
|
|
452
584
|
}
|
package/lib/modules/selection.js
CHANGED
|
@@ -1648,6 +1648,7 @@ function deleteSelectedCellFormat(ctx) {
|
|
|
1648
1648
|
return "success";
|
|
1649
1649
|
}
|
|
1650
1650
|
function fillRightData(ctx) {
|
|
1651
|
+
var _a, _b;
|
|
1651
1652
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1652
1653
|
if (allowEdit === false) {
|
|
1653
1654
|
return "allowEdit";
|
|
@@ -1675,10 +1676,20 @@ function fillRightData(ctx) {
|
|
|
1675
1676
|
var r2 = selection[s].row[1];
|
|
1676
1677
|
var c1 = selection[s].column[0];
|
|
1677
1678
|
var c2 = selection[s].column[1];
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
d[
|
|
1679
|
+
var isSingleCell = r1 === r2 && c1 === c2;
|
|
1680
|
+
if (isSingleCell) {
|
|
1681
|
+
if (c1 - 1 >= 0 && d[r1]) {
|
|
1682
|
+
var prev = d[r1][c1 - 1];
|
|
1683
|
+
d[r1][c1] = prev != null ? __assign({}, prev) : {};
|
|
1684
|
+
}
|
|
1685
|
+
} else {
|
|
1686
|
+
for (var r = r1; r <= r2; r += 1) {
|
|
1687
|
+
var sourceCell = (_a = d[r]) === null || _a === void 0 ? void 0 : _a[c1];
|
|
1688
|
+
for (var c = c1 + 1; c <= c2; c += 1) {
|
|
1689
|
+
if (d[r]) {
|
|
1690
|
+
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1682
1693
|
}
|
|
1683
1694
|
}
|
|
1684
1695
|
}
|
|
@@ -1686,6 +1697,7 @@ function fillRightData(ctx) {
|
|
|
1686
1697
|
return "success";
|
|
1687
1698
|
}
|
|
1688
1699
|
function fillDownData(ctx) {
|
|
1700
|
+
var _a, _b;
|
|
1689
1701
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1690
1702
|
if (allowEdit === false) {
|
|
1691
1703
|
return "allowEdit";
|
|
@@ -1713,10 +1725,20 @@ function fillDownData(ctx) {
|
|
|
1713
1725
|
var r2 = selection[s].row[1];
|
|
1714
1726
|
var c1 = selection[s].column[0];
|
|
1715
1727
|
var c2 = selection[s].column[1];
|
|
1716
|
-
|
|
1728
|
+
var isSingleCell = r1 === r2 && c1 === c2;
|
|
1729
|
+
if (isSingleCell) {
|
|
1730
|
+
if (r1 - 1 >= 0 && d[r1 - 1]) {
|
|
1731
|
+
var prev = d[r1 - 1][c1];
|
|
1732
|
+
if (!d[r1]) d[r1] = [];
|
|
1733
|
+
d[r1][c1] = prev != null ? __assign({}, prev) : {};
|
|
1734
|
+
}
|
|
1735
|
+
} else {
|
|
1717
1736
|
for (var c = c1; c <= c2; c += 1) {
|
|
1718
|
-
var
|
|
1719
|
-
|
|
1737
|
+
var sourceCell = (_a = d[r1]) === null || _a === void 0 ? void 0 : _a[c];
|
|
1738
|
+
for (var r = r1 + 1; r <= r2; r += 1) {
|
|
1739
|
+
if (!d[r]) d[r] = [];
|
|
1740
|
+
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_b = d[r][c]) !== null && _b !== void 0 ? _b : {};
|
|
1741
|
+
}
|
|
1720
1742
|
}
|
|
1721
1743
|
}
|
|
1722
1744
|
}
|
package/lib/modules/toolbar.d.ts
CHANGED
|
@@ -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 {};
|
package/lib/modules/toolbar.js
CHANGED
|
@@ -37,6 +37,7 @@ var _utils = require("../utils");
|
|
|
37
37
|
var _cell = require("./cell");
|
|
38
38
|
var _color = require("./color");
|
|
39
39
|
var _format = require("./format");
|
|
40
|
+
var _cursor = require("./cursor");
|
|
40
41
|
var _formula2 = require("./formula");
|
|
41
42
|
var _inlineString = require("./inline-string");
|
|
42
43
|
var _location = require("./location");
|
|
@@ -1002,15 +1003,36 @@ function handleTextSize(ctx, cellInput, size, canvas) {
|
|
|
1002
1003
|
function handleSum(ctx, cellInput, fxInput, cache) {
|
|
1003
1004
|
autoSelectionFormula(ctx, cellInput, fxInput, "SUM", cache);
|
|
1004
1005
|
}
|
|
1005
|
-
function handleLink(ctx) {
|
|
1006
|
-
var _a;
|
|
1006
|
+
function handleLink(ctx, cellInput) {
|
|
1007
|
+
var _a, _b, _c;
|
|
1007
1008
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1008
1009
|
if (!allowEdit) return;
|
|
1009
1010
|
var selection = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
|
|
1010
1011
|
var flowdata = (0, _context.getFlowdata)(ctx);
|
|
1011
|
-
if (flowdata
|
|
1012
|
-
|
|
1012
|
+
if (flowdata == null || selection == null) return;
|
|
1013
|
+
var r = selection.row[0];
|
|
1014
|
+
var c = selection.column[0];
|
|
1015
|
+
var isEditMode = ((_b = ctx.luckysheetCellUpdate) === null || _b === void 0 ? void 0 : _b.length) === 2 && ctx.luckysheetCellUpdate[0] === r && ctx.luckysheetCellUpdate[1] === c;
|
|
1016
|
+
var applyToSelection = false;
|
|
1017
|
+
var originText;
|
|
1018
|
+
var selectionOffsets;
|
|
1019
|
+
if (isEditMode && cellInput) {
|
|
1020
|
+
var sel = window.getSelection();
|
|
1021
|
+
if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed && cellInput.contains(sel.anchorNode)) {
|
|
1022
|
+
var value = (_c = cellInput.innerText) !== null && _c !== void 0 ? _c : "";
|
|
1023
|
+
if (value.substring(0, 1) !== "=") {
|
|
1024
|
+
originText = sel.toString();
|
|
1025
|
+
applyToSelection = true;
|
|
1026
|
+
var off = (0, _cursor.getSelectionCharacterOffsets)(cellInput);
|
|
1027
|
+
if (off) selectionOffsets = off;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1013
1030
|
}
|
|
1031
|
+
(0, _hyperlink.showLinkCard)(ctx, r, c, {
|
|
1032
|
+
applyToSelection: applyToSelection || undefined,
|
|
1033
|
+
originText: originText,
|
|
1034
|
+
selectionOffsets: selectionOffsets
|
|
1035
|
+
}, true, false);
|
|
1014
1036
|
}
|
|
1015
1037
|
var handlerMap = {
|
|
1016
1038
|
"currency-format": handleCurrencyFormat,
|