@fileverse-dev/fortune-core 1.3.12 → 1.3.13-create-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/events/keyboard.d.ts +2 -2
- package/es/events/keyboard.js +204 -30
- package/es/events/mouse.js +79 -44
- package/es/events/paste.js +240 -56
- package/es/locale/en.d.ts +3 -0
- package/es/locale/en.js +3 -0
- package/es/locale/es.d.ts +3 -0
- package/es/locale/es.js +3 -0
- package/es/locale/hi.d.ts +3 -0
- package/es/locale/hi.js +3 -0
- package/es/locale/index.d.ts +3 -0
- package/es/locale/zh.d.ts +3 -0
- package/es/locale/zh.js +3 -0
- package/es/locale/zh_tw.d.ts +3 -0
- package/es/locale/zh_tw.js +3 -0
- package/es/modules/ConditionFormat.js +26 -0
- package/es/modules/cell.d.ts +5 -1
- package/es/modules/cell.js +182 -38
- package/es/modules/clipboard.js +111 -2
- package/es/modules/format.js +12 -7
- package/es/modules/formula.d.ts +23 -0
- package/es/modules/formula.js +610 -51
- package/es/modules/hyperlink.js +18 -6
- package/es/modules/inline-string.js +61 -8
- package/es/modules/moveCells.js +52 -9
- package/es/modules/selection.d.ts +1 -0
- package/es/modules/selection.js +102 -16
- package/es/modules/validation.js +6 -3
- package/es/paste-helpers/calculate-range-cell-size.js +5 -4
- package/es/paste-table-helpers.d.ts +1 -1
- package/es/paste-table-helpers.js +170 -21
- package/es/types.d.ts +3 -0
- package/lib/events/keyboard.d.ts +2 -2
- package/lib/events/keyboard.js +203 -29
- package/lib/events/mouse.js +78 -43
- package/lib/events/paste.js +238 -54
- package/lib/locale/en.d.ts +3 -0
- package/lib/locale/en.js +3 -0
- package/lib/locale/es.d.ts +3 -0
- package/lib/locale/es.js +3 -0
- package/lib/locale/hi.d.ts +3 -0
- package/lib/locale/hi.js +3 -0
- package/lib/locale/index.d.ts +3 -0
- package/lib/locale/zh.d.ts +3 -0
- package/lib/locale/zh.js +3 -0
- package/lib/locale/zh_tw.d.ts +3 -0
- package/lib/locale/zh_tw.js +3 -0
- package/lib/modules/ConditionFormat.js +26 -0
- package/lib/modules/cell.d.ts +5 -1
- package/lib/modules/cell.js +180 -36
- package/lib/modules/clipboard.js +111 -2
- package/lib/modules/format.js +12 -7
- package/lib/modules/formula.d.ts +23 -0
- package/lib/modules/formula.js +623 -51
- package/lib/modules/hyperlink.js +18 -6
- package/lib/modules/inline-string.js +61 -8
- package/lib/modules/moveCells.js +52 -9
- package/lib/modules/selection.d.ts +1 -0
- package/lib/modules/selection.js +101 -15
- package/lib/modules/validation.js +6 -3
- package/lib/paste-helpers/calculate-range-cell-size.js +5 -4
- package/lib/paste-table-helpers.d.ts +1 -1
- package/lib/paste-table-helpers.js +170 -21
- package/lib/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -9,12 +9,22 @@ var __assign = this && this.__assign || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
12
20
|
import _ from "lodash";
|
|
13
21
|
import { locale } from "./locale";
|
|
14
22
|
import { getQKBorder, saveHyperlink } from "./modules";
|
|
15
23
|
import { getSheetIndex } from "./utils";
|
|
16
24
|
import { setRowHeight, setColumnWidth } from "./api";
|
|
17
|
-
|
|
25
|
+
import { adjustFormulaForPaste } from "./events/paste";
|
|
26
|
+
import { convertSpanToShareString } from "./modules/inline-string";
|
|
27
|
+
export var DEFAULT_FONT_SIZE = 10;
|
|
18
28
|
var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
|
|
19
29
|
var patternReg = /{([^}]*)}/g;
|
|
20
30
|
var patternStyle = styleInner.match(patternReg);
|
|
@@ -50,6 +60,90 @@ var mapFontFamilyToIndex = function mapFontFamilyToIndex(ff, ctx) {
|
|
|
50
60
|
if (found != null) return locale_fontjson[found];
|
|
51
61
|
return 0;
|
|
52
62
|
};
|
|
63
|
+
var BLOCK_TAGS = new Set(["p", "div", "li", "tr", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
64
|
+
var getInlineStringSegmentsFromTd = function getInlineStringSegmentsFromTd(td, cell, defaultFontSize) {
|
|
65
|
+
var segments = [];
|
|
66
|
+
function walk(node, css, link) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
69
|
+
var text = node.textContent || "";
|
|
70
|
+
if (text) {
|
|
71
|
+
var span = document.createElement("span");
|
|
72
|
+
var cssText = Object.entries(css).map(function (_a) {
|
|
73
|
+
var k = _a[0],
|
|
74
|
+
v = _a[1];
|
|
75
|
+
return "".concat(k, ":").concat(v);
|
|
76
|
+
}).join(";");
|
|
77
|
+
if (cssText) span.setAttribute("style", cssText);
|
|
78
|
+
span.textContent = text;
|
|
79
|
+
if (link) {
|
|
80
|
+
span.dataset.linkType = link.type;
|
|
81
|
+
span.dataset.linkAddress = link.address;
|
|
82
|
+
}
|
|
83
|
+
segments.push(span);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
88
|
+
var el = node;
|
|
89
|
+
var tag = el.tagName.toLowerCase();
|
|
90
|
+
if (tag === "br") {
|
|
91
|
+
var span = document.createElement("span");
|
|
92
|
+
span.textContent = "\n";
|
|
93
|
+
segments.push(span);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (BLOCK_TAGS.has(tag) && segments.length > 0) {
|
|
97
|
+
var nl = document.createElement("span");
|
|
98
|
+
nl.textContent = "\n";
|
|
99
|
+
segments.push(nl);
|
|
100
|
+
}
|
|
101
|
+
var newCss = __assign({}, css);
|
|
102
|
+
if (tag === "b" || tag === "strong") newCss["font-weight"] = "bold";
|
|
103
|
+
if (tag === "i" || tag === "em") newCss["font-style"] = "italic";
|
|
104
|
+
if (tag === "u") newCss["text-decoration"] = "underline";
|
|
105
|
+
if (tag === "s" || tag === "strike") {
|
|
106
|
+
newCss["text-decoration"] = "line-through";
|
|
107
|
+
}
|
|
108
|
+
if ((_a = el.style) === null || _a === void 0 ? void 0 : _a.cssText) {
|
|
109
|
+
Array.from(el.style).forEach(function (prop) {
|
|
110
|
+
if (prop === "font-size") return;
|
|
111
|
+
var val = el.style.getPropertyValue(prop);
|
|
112
|
+
if (val) newCss[prop] = val;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
var newLink = link;
|
|
116
|
+
if (tag === "a") {
|
|
117
|
+
var href = ((_b = el.getAttribute("href")) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
|
118
|
+
if (/^https?:\/\//i.test(href)) {
|
|
119
|
+
newLink = {
|
|
120
|
+
type: "webpage",
|
|
121
|
+
address: href
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Array.from(el.childNodes).forEach(function (child) {
|
|
126
|
+
walk(child, newCss, newLink);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
walk(td, {});
|
|
130
|
+
if (segments.length === 0) return [];
|
|
131
|
+
var base = {
|
|
132
|
+
fc: cell.fc || "#000000",
|
|
133
|
+
fs: cell.fs || defaultFontSize,
|
|
134
|
+
cl: cell.cl || 0,
|
|
135
|
+
un: cell.un || 0,
|
|
136
|
+
bl: cell.bl || 0,
|
|
137
|
+
it: cell.it || 0,
|
|
138
|
+
ff: cell.ff || 0
|
|
139
|
+
};
|
|
140
|
+
var result = convertSpanToShareString(segments, base);
|
|
141
|
+
return result.map(function (seg) {
|
|
142
|
+
return __assign(__assign(__assign({}, base), seg), {
|
|
143
|
+
fs: base.fs
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
53
147
|
function applyBordersAndMerges(td, startRow, startCol, absRow, absCol, rowSpanCount, colSpanCount, borderInfo, data) {
|
|
54
148
|
var topBorder = td.style.borderTop && !td.style.borderTop.startsWith("0px") ? getQKBorder(td.style.borderTopWidth, td.style.borderTopStyle, td.style.borderTopColor) : null;
|
|
55
149
|
var bottomBorder = td.style.borderBottom && !td.style.borderBottom.startsWith("0px") ? getQKBorder(td.style.borderBottomWidth, td.style.borderBottomStyle, td.style.borderBottomColor) : null;
|
|
@@ -109,7 +203,9 @@ var detectHyperlink = function detectHyperlink(td) {
|
|
|
109
203
|
if (anchor) {
|
|
110
204
|
var href = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
111
205
|
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || href;
|
|
112
|
-
|
|
206
|
+
var cellText = (td.textContent || "").trim();
|
|
207
|
+
var anchorText = (anchor.textContent || "").trim();
|
|
208
|
+
if (href && urlRegex.test(href) && cellText === anchorText) return {
|
|
113
209
|
href: href,
|
|
114
210
|
display: display
|
|
115
211
|
};
|
|
@@ -123,34 +219,63 @@ var detectHyperlink = function detectHyperlink(td) {
|
|
|
123
219
|
return null;
|
|
124
220
|
};
|
|
125
221
|
function brToNewline(str) {
|
|
126
|
-
return str.replace(/<br\s*\/?>/gi, "\n");
|
|
222
|
+
return str.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(div|p|li)>/gi, "\n");
|
|
127
223
|
}
|
|
128
224
|
var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
129
|
-
var _a, _b, _c, _d;
|
|
225
|
+
var _a, _b, _c, _d, _e;
|
|
226
|
+
var fortuneCellAttr = td.getAttribute("data-fortune-cell");
|
|
227
|
+
if (fortuneCellAttr) {
|
|
228
|
+
try {
|
|
229
|
+
var _f = JSON.parse(decodeURIComponent(fortuneCellAttr)),
|
|
230
|
+
_srcRow = _f._srcRow,
|
|
231
|
+
_srcCol = _f._srcCol,
|
|
232
|
+
parsed = __rest(_f, ["_srcRow", "_srcCol"]);
|
|
233
|
+
var cell_1 = parsed;
|
|
234
|
+
delete cell_1.mc;
|
|
235
|
+
delete cell_1.hl;
|
|
236
|
+
var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
237
|
+
var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
238
|
+
return {
|
|
239
|
+
cell: cell_1,
|
|
240
|
+
rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
|
|
241
|
+
colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
|
|
242
|
+
hyperlink: detectHyperlink(td),
|
|
243
|
+
srcRow: _srcRow,
|
|
244
|
+
srcCol: _srcCol
|
|
245
|
+
};
|
|
246
|
+
} catch (_g) {}
|
|
247
|
+
}
|
|
130
248
|
var cell = {};
|
|
131
|
-
var
|
|
132
|
-
var
|
|
133
|
-
|
|
249
|
+
var rawHtml = td.innerHTML || "";
|
|
250
|
+
var hasHtmlLineBreak = /<br\s*\/?>|<\/(div|p|li)>/i.test(rawHtml);
|
|
251
|
+
var domText = td.innerText || td.textContent || "";
|
|
252
|
+
var htmlText = brToNewline(rawHtml).replace(/<[^>]*>/g, "");
|
|
253
|
+
var rawText = (hasHtmlLineBreak && !/[\r\n]/.test(domText) ? htmlText : domText || htmlText || rawHtml || "").trim();
|
|
254
|
+
var normalizedText = rawText.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
255
|
+
var isLineBreak = hasHtmlLineBreak || normalizedText.includes("\n");
|
|
256
|
+
if (!normalizedText) {
|
|
134
257
|
cell.v = undefined;
|
|
135
258
|
cell.m = "";
|
|
136
259
|
} else if (isLineBreak) {
|
|
137
|
-
|
|
260
|
+
cell.v = normalizedText;
|
|
261
|
+
cell.m = normalizedText;
|
|
138
262
|
cell = __assign(__assign({}, cell), {
|
|
139
|
-
ct:
|
|
263
|
+
ct: {
|
|
264
|
+
fa: "General",
|
|
140
265
|
t: "inlineStr",
|
|
141
266
|
s: [{
|
|
142
|
-
v:
|
|
267
|
+
v: normalizedText
|
|
143
268
|
}]
|
|
144
|
-
}
|
|
269
|
+
}
|
|
145
270
|
});
|
|
146
271
|
} else {
|
|
147
|
-
cell.v =
|
|
148
|
-
cell.m =
|
|
272
|
+
cell.v = normalizedText;
|
|
273
|
+
cell.m = normalizedText;
|
|
149
274
|
cell.ct = {
|
|
150
275
|
fa: "General",
|
|
151
276
|
t: "g"
|
|
152
277
|
};
|
|
153
|
-
if (HEX_REGEX.test(
|
|
278
|
+
if (HEX_REGEX.test(normalizedText)) {
|
|
154
279
|
cell.ct = {
|
|
155
280
|
fa: "@",
|
|
156
281
|
t: "s"
|
|
@@ -173,11 +298,13 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
173
298
|
var fontWeight = td.style.fontWeight;
|
|
174
299
|
cell.bl = (fontWeight.toString() === "400" || fontWeight === "normal" || _.isEmpty(fontWeight)) && !_.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
175
300
|
cell.it = (td.style.fontStyle === "normal" || _.isEmpty(td.style.fontStyle)) && !_.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
176
|
-
|
|
177
|
-
cell.
|
|
301
|
+
var textDecoration = [td.style.textDecoration, td.style.textDecorationLine, styles["text-decoration"], styles["text-decoration-line"]].filter(Boolean).join(" ").toLowerCase();
|
|
302
|
+
cell.un = textDecoration.includes("underline") ? 1 : undefined;
|
|
303
|
+
cell.cl = textDecoration.includes("line-through") || _.includes(td.innerHTML, "<s>") ? 1 : undefined;
|
|
178
304
|
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
179
305
|
cell.ff = mapFontFamilyToIndex(ff, ctx);
|
|
180
|
-
var
|
|
306
|
+
var ctxDefaultFontSize = (_d = ctx.defaultFontSize) !== null && _d !== void 0 ? _d : DEFAULT_FONT_SIZE;
|
|
307
|
+
var fontSize = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "".concat(ctxDefaultFontSize), 10));
|
|
181
308
|
cell.fs = fontSize;
|
|
182
309
|
cell.fc = td.style.color || styles.color;
|
|
183
310
|
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
@@ -188,12 +315,27 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
188
315
|
} else {
|
|
189
316
|
cell.ht = 1;
|
|
190
317
|
}
|
|
191
|
-
if (((
|
|
318
|
+
if (((_e = td === null || td === void 0 ? void 0 : td.style) === null || _e === void 0 ? void 0 : _e["overflow-wrap"]) === "anywhere") {
|
|
192
319
|
cell.tb = "2";
|
|
193
320
|
} else {
|
|
194
|
-
cell.tb = "
|
|
321
|
+
cell.tb = "1";
|
|
195
322
|
}
|
|
196
323
|
if ("mso-rotate" in styles) cell.rt = parseFloat(styles["mso-rotate"]);
|
|
324
|
+
var inlineSegments = getInlineStringSegmentsFromTd(td, cell, ctxDefaultFontSize);
|
|
325
|
+
var segmentsText = inlineSegments.map(function (s) {
|
|
326
|
+
var _a;
|
|
327
|
+
return (_a = s.v) !== null && _a !== void 0 ? _a : "";
|
|
328
|
+
}).join("");
|
|
329
|
+
var shouldUseInlineString = normalizedText.length > 0 && inlineSegments.length > 0 && segmentsText.trim().length > 0 && (isLineBreak || td.querySelector("[data-sheets-root]") != null || td.querySelector("span[style], b, strong, i, em, u, s, strike, a[href]") != null);
|
|
330
|
+
if (shouldUseInlineString) {
|
|
331
|
+
cell.v = normalizedText;
|
|
332
|
+
cell.m = normalizedText;
|
|
333
|
+
cell.ct = {
|
|
334
|
+
fa: "General",
|
|
335
|
+
t: "inlineStr",
|
|
336
|
+
s: inlineSegments
|
|
337
|
+
};
|
|
338
|
+
}
|
|
197
339
|
var rowspan = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
198
340
|
var colspan = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
199
341
|
if (Number.isNaN(rowspan)) rowspan = 1;
|
|
@@ -207,7 +349,7 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
207
349
|
};
|
|
208
350
|
export function handlePastedTable(ctx, html, pasteHandler) {
|
|
209
351
|
var _a;
|
|
210
|
-
if (
|
|
352
|
+
if (!/<table[\s/>]/i.test(html)) return;
|
|
211
353
|
var containerDiv = document.createElement("div");
|
|
212
354
|
containerDiv.innerHTML = html;
|
|
213
355
|
var tableColGropup = containerDiv.querySelectorAll("colgroup");
|
|
@@ -277,10 +419,17 @@ export function handlePastedTable(ctx, html, pasteHandler) {
|
|
|
277
419
|
cell = _a.cell,
|
|
278
420
|
rowspan = _a.rowspan,
|
|
279
421
|
colspan = _a.colspan,
|
|
280
|
-
hyperlink = _a.hyperlink
|
|
422
|
+
hyperlink = _a.hyperlink,
|
|
423
|
+
srcRow = _a.srcRow,
|
|
424
|
+
srcCol = _a.srcCol;
|
|
281
425
|
var anchorCol = ctx.luckysheet_select_save[0].column[0];
|
|
282
426
|
var absoluteRow = anchorRow + localRowIndex;
|
|
283
427
|
var absoluteCol = anchorCol + localColIndex;
|
|
428
|
+
if (cell.f && srcRow != null && srcCol != null) {
|
|
429
|
+
try {
|
|
430
|
+
cell.f = adjustFormulaForPaste(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
|
|
431
|
+
} catch (_b) {}
|
|
432
|
+
}
|
|
284
433
|
pastedMatrix[localRowIndex][localColIndex] = cell;
|
|
285
434
|
if (hyperlink) {
|
|
286
435
|
saveHyperlink(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
|
package/es/types.d.ts
CHANGED
|
@@ -325,9 +325,12 @@ export type Freezen = {
|
|
|
325
325
|
};
|
|
326
326
|
};
|
|
327
327
|
export type GlobalCache = {
|
|
328
|
+
enteredEditByTyping?: boolean;
|
|
329
|
+
pendingTypeOverCell?: [number, number];
|
|
328
330
|
verticalScrollLock?: boolean;
|
|
329
331
|
horizontalScrollLock?: boolean;
|
|
330
332
|
overwriteCell?: boolean;
|
|
333
|
+
overwriteCellFirstChar?: string;
|
|
331
334
|
ignoreWriteCell?: boolean;
|
|
332
335
|
doNotFocus?: boolean;
|
|
333
336
|
doNotUpdateCell?: boolean;
|
package/lib/events/keyboard.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from "../context";
|
|
2
2
|
import { GlobalCache } from "../types";
|
|
3
|
-
export declare function handleGlobalEnter(ctx: Context, cellInput: HTMLDivElement, e: KeyboardEvent, canvas?: CanvasRenderingContext2D): void;
|
|
4
|
-
export declare function handleWithCtrlOrMetaKey(ctx: Context, cache: GlobalCache, e: KeyboardEvent, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, handleUndo: () => void, handleRedo: () => void): void;
|
|
3
|
+
export declare function handleGlobalEnter(ctx: Context, cellInput: HTMLDivElement, e: KeyboardEvent, cache: GlobalCache, canvas?: CanvasRenderingContext2D): void;
|
|
4
|
+
export declare function handleWithCtrlOrMetaKey(ctx: Context, cache: GlobalCache, e: KeyboardEvent, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, handleUndo: () => void, handleRedo: () => void, canvas?: CanvasRenderingContext2D): void;
|
|
5
5
|
export declare function handleArrowKey(ctx: Context, e: KeyboardEvent): void;
|
|
6
6
|
export declare function handleGlobalKeyDown(ctx: Context, cellInput: HTMLDivElement, fxInput: HTMLDivElement | null | undefined, e: KeyboardEvent, cache: GlobalCache, handleUndo: () => void, handleRedo: () => void, canvas?: CanvasRenderingContext2D): Promise<void>;
|