@fileverse-dev/fortune-core 1.3.12 → 1.3.13-create-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/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 +177 -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 +4 -1
- package/es/modules/cell.js +124 -15
- 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 +21 -4
- 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 +175 -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 +4 -1
- package/lib/modules/cell.js +123 -14
- 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 +21 -4
- 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
|
@@ -10,6 +10,8 @@ var _locale = require("./locale");
|
|
|
10
10
|
var _modules = require("./modules");
|
|
11
11
|
var _utils = require("./utils");
|
|
12
12
|
var _api = require("./api");
|
|
13
|
+
var _paste = require("./events/paste");
|
|
14
|
+
var _inlineString = require("./modules/inline-string");
|
|
13
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
16
|
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); }
|
|
15
17
|
var __assign = void 0 && (void 0).__assign || function () {
|
|
@@ -22,7 +24,15 @@ var __assign = void 0 && (void 0).__assign || function () {
|
|
|
22
24
|
};
|
|
23
25
|
return __assign.apply(this, arguments);
|
|
24
26
|
};
|
|
25
|
-
var
|
|
27
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
28
|
+
var t = {};
|
|
29
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
30
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
32
|
+
}
|
|
33
|
+
return t;
|
|
34
|
+
};
|
|
35
|
+
var DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_SIZE = 10;
|
|
26
36
|
var parseStylesheetPairs = function parseStylesheetPairs(styleInner) {
|
|
27
37
|
var patternReg = /{([^}]*)}/g;
|
|
28
38
|
var patternStyle = styleInner.match(patternReg);
|
|
@@ -58,6 +68,90 @@ var mapFontFamilyToIndex = function mapFontFamilyToIndex(ff, ctx) {
|
|
|
58
68
|
if (found != null) return locale_fontjson[found];
|
|
59
69
|
return 0;
|
|
60
70
|
};
|
|
71
|
+
var BLOCK_TAGS = new Set(["p", "div", "li", "tr", "blockquote", "h1", "h2", "h3", "h4", "h5", "h6"]);
|
|
72
|
+
var getInlineStringSegmentsFromTd = function getInlineStringSegmentsFromTd(td, cell, defaultFontSize) {
|
|
73
|
+
var segments = [];
|
|
74
|
+
function walk(node, css, link) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
77
|
+
var text = node.textContent || "";
|
|
78
|
+
if (text) {
|
|
79
|
+
var span = document.createElement("span");
|
|
80
|
+
var cssText = Object.entries(css).map(function (_a) {
|
|
81
|
+
var k = _a[0],
|
|
82
|
+
v = _a[1];
|
|
83
|
+
return "".concat(k, ":").concat(v);
|
|
84
|
+
}).join(";");
|
|
85
|
+
if (cssText) span.setAttribute("style", cssText);
|
|
86
|
+
span.textContent = text;
|
|
87
|
+
if (link) {
|
|
88
|
+
span.dataset.linkType = link.type;
|
|
89
|
+
span.dataset.linkAddress = link.address;
|
|
90
|
+
}
|
|
91
|
+
segments.push(span);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return;
|
|
96
|
+
var el = node;
|
|
97
|
+
var tag = el.tagName.toLowerCase();
|
|
98
|
+
if (tag === "br") {
|
|
99
|
+
var span = document.createElement("span");
|
|
100
|
+
span.textContent = "\n";
|
|
101
|
+
segments.push(span);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (BLOCK_TAGS.has(tag) && segments.length > 0) {
|
|
105
|
+
var nl = document.createElement("span");
|
|
106
|
+
nl.textContent = "\n";
|
|
107
|
+
segments.push(nl);
|
|
108
|
+
}
|
|
109
|
+
var newCss = __assign({}, css);
|
|
110
|
+
if (tag === "b" || tag === "strong") newCss["font-weight"] = "bold";
|
|
111
|
+
if (tag === "i" || tag === "em") newCss["font-style"] = "italic";
|
|
112
|
+
if (tag === "u") newCss["text-decoration"] = "underline";
|
|
113
|
+
if (tag === "s" || tag === "strike") {
|
|
114
|
+
newCss["text-decoration"] = "line-through";
|
|
115
|
+
}
|
|
116
|
+
if ((_a = el.style) === null || _a === void 0 ? void 0 : _a.cssText) {
|
|
117
|
+
Array.from(el.style).forEach(function (prop) {
|
|
118
|
+
if (prop === "font-size") return;
|
|
119
|
+
var val = el.style.getPropertyValue(prop);
|
|
120
|
+
if (val) newCss[prop] = val;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
var newLink = link;
|
|
124
|
+
if (tag === "a") {
|
|
125
|
+
var href = ((_b = el.getAttribute("href")) === null || _b === void 0 ? void 0 : _b.trim()) || "";
|
|
126
|
+
if (/^https?:\/\//i.test(href)) {
|
|
127
|
+
newLink = {
|
|
128
|
+
type: "webpage",
|
|
129
|
+
address: href
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
Array.from(el.childNodes).forEach(function (child) {
|
|
134
|
+
walk(child, newCss, newLink);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
walk(td, {});
|
|
138
|
+
if (segments.length === 0) return [];
|
|
139
|
+
var base = {
|
|
140
|
+
fc: cell.fc || "#000000",
|
|
141
|
+
fs: cell.fs || defaultFontSize,
|
|
142
|
+
cl: cell.cl || 0,
|
|
143
|
+
un: cell.un || 0,
|
|
144
|
+
bl: cell.bl || 0,
|
|
145
|
+
it: cell.it || 0,
|
|
146
|
+
ff: cell.ff || 0
|
|
147
|
+
};
|
|
148
|
+
var result = (0, _inlineString.convertSpanToShareString)(segments, base);
|
|
149
|
+
return result.map(function (seg) {
|
|
150
|
+
return __assign(__assign(__assign({}, base), seg), {
|
|
151
|
+
fs: base.fs
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
};
|
|
61
155
|
function applyBordersAndMerges(td, startRow, startCol, absRow, absCol, rowSpanCount, colSpanCount, borderInfo, data) {
|
|
62
156
|
var topBorder = td.style.borderTop && !td.style.borderTop.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderTopWidth, td.style.borderTopStyle, td.style.borderTopColor) : null;
|
|
63
157
|
var bottomBorder = td.style.borderBottom && !td.style.borderBottom.startsWith("0px") ? (0, _modules.getQKBorder)(td.style.borderBottomWidth, td.style.borderBottomStyle, td.style.borderBottomColor) : null;
|
|
@@ -117,7 +211,9 @@ var detectHyperlink = function detectHyperlink(td) {
|
|
|
117
211
|
if (anchor) {
|
|
118
212
|
var href = ((_a = anchor.getAttribute("href")) === null || _a === void 0 ? void 0 : _a.trim()) || "";
|
|
119
213
|
var display = ((_b = anchor.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || href;
|
|
120
|
-
|
|
214
|
+
var cellText = (td.textContent || "").trim();
|
|
215
|
+
var anchorText = (anchor.textContent || "").trim();
|
|
216
|
+
if (href && urlRegex.test(href) && cellText === anchorText) return {
|
|
121
217
|
href: href,
|
|
122
218
|
display: display
|
|
123
219
|
};
|
|
@@ -131,34 +227,63 @@ var detectHyperlink = function detectHyperlink(td) {
|
|
|
131
227
|
return null;
|
|
132
228
|
};
|
|
133
229
|
function brToNewline(str) {
|
|
134
|
-
return str.replace(/<br\s*\/?>/gi, "\n");
|
|
230
|
+
return str.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(div|p|li)>/gi, "\n");
|
|
135
231
|
}
|
|
136
232
|
var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
137
|
-
var _a, _b, _c, _d;
|
|
233
|
+
var _a, _b, _c, _d, _e;
|
|
234
|
+
var fortuneCellAttr = td.getAttribute("data-fortune-cell");
|
|
235
|
+
if (fortuneCellAttr) {
|
|
236
|
+
try {
|
|
237
|
+
var _f = JSON.parse(decodeURIComponent(fortuneCellAttr)),
|
|
238
|
+
_srcRow = _f._srcRow,
|
|
239
|
+
_srcCol = _f._srcCol,
|
|
240
|
+
parsed = __rest(_f, ["_srcRow", "_srcCol"]);
|
|
241
|
+
var cell_1 = parsed;
|
|
242
|
+
delete cell_1.mc;
|
|
243
|
+
delete cell_1.hl;
|
|
244
|
+
var rowspan_1 = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
245
|
+
var colspan_1 = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
246
|
+
return {
|
|
247
|
+
cell: cell_1,
|
|
248
|
+
rowspan: Number.isNaN(rowspan_1) ? 1 : rowspan_1,
|
|
249
|
+
colspan: Number.isNaN(colspan_1) ? 1 : colspan_1,
|
|
250
|
+
hyperlink: detectHyperlink(td),
|
|
251
|
+
srcRow: _srcRow,
|
|
252
|
+
srcCol: _srcCol
|
|
253
|
+
};
|
|
254
|
+
} catch (_g) {}
|
|
255
|
+
}
|
|
138
256
|
var cell = {};
|
|
139
|
-
var
|
|
140
|
-
var
|
|
141
|
-
|
|
257
|
+
var rawHtml = td.innerHTML || "";
|
|
258
|
+
var hasHtmlLineBreak = /<br\s*\/?>|<\/(div|p|li)>/i.test(rawHtml);
|
|
259
|
+
var domText = td.innerText || td.textContent || "";
|
|
260
|
+
var htmlText = brToNewline(rawHtml).replace(/<[^>]*>/g, "");
|
|
261
|
+
var rawText = (hasHtmlLineBreak && !/[\r\n]/.test(domText) ? htmlText : domText || htmlText || rawHtml || "").trim();
|
|
262
|
+
var normalizedText = rawText.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
263
|
+
var isLineBreak = hasHtmlLineBreak || normalizedText.includes("\n");
|
|
264
|
+
if (!normalizedText) {
|
|
142
265
|
cell.v = undefined;
|
|
143
266
|
cell.m = "";
|
|
144
267
|
} else if (isLineBreak) {
|
|
145
|
-
|
|
268
|
+
cell.v = normalizedText;
|
|
269
|
+
cell.m = normalizedText;
|
|
146
270
|
cell = __assign(__assign({}, cell), {
|
|
147
|
-
ct:
|
|
271
|
+
ct: {
|
|
272
|
+
fa: "General",
|
|
148
273
|
t: "inlineStr",
|
|
149
274
|
s: [{
|
|
150
|
-
v:
|
|
275
|
+
v: normalizedText
|
|
151
276
|
}]
|
|
152
|
-
}
|
|
277
|
+
}
|
|
153
278
|
});
|
|
154
279
|
} else {
|
|
155
|
-
cell.v =
|
|
156
|
-
cell.m =
|
|
280
|
+
cell.v = normalizedText;
|
|
281
|
+
cell.m = normalizedText;
|
|
157
282
|
cell.ct = {
|
|
158
283
|
fa: "General",
|
|
159
284
|
t: "g"
|
|
160
285
|
};
|
|
161
|
-
if (HEX_REGEX.test(
|
|
286
|
+
if (HEX_REGEX.test(normalizedText)) {
|
|
162
287
|
cell.ct = {
|
|
163
288
|
fa: "@",
|
|
164
289
|
t: "s"
|
|
@@ -181,11 +306,13 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
181
306
|
var fontWeight = td.style.fontWeight;
|
|
182
307
|
cell.bl = (fontWeight.toString() === "400" || fontWeight === "normal" || _lodash.default.isEmpty(fontWeight)) && !_lodash.default.includes(styles["font-style"], "bold") && (!styles["font-weight"] || styles["font-weight"] === "400") ? 0 : 1;
|
|
183
308
|
cell.it = (td.style.fontStyle === "normal" || _lodash.default.isEmpty(td.style.fontStyle)) && !_lodash.default.includes(styles["font-style"], "italic") ? 0 : 1;
|
|
184
|
-
|
|
185
|
-
cell.
|
|
309
|
+
var textDecoration = [td.style.textDecoration, td.style.textDecorationLine, styles["text-decoration"], styles["text-decoration-line"]].filter(Boolean).join(" ").toLowerCase();
|
|
310
|
+
cell.un = textDecoration.includes("underline") ? 1 : undefined;
|
|
311
|
+
cell.cl = textDecoration.includes("line-through") || _lodash.default.includes(td.innerHTML, "<s>") ? 1 : undefined;
|
|
186
312
|
var ff = td.style.fontFamily || styles["font-family"] || "";
|
|
187
313
|
cell.ff = mapFontFamilyToIndex(ff, ctx);
|
|
188
|
-
var
|
|
314
|
+
var ctxDefaultFontSize = (_d = ctx.defaultFontSize) !== null && _d !== void 0 ? _d : DEFAULT_FONT_SIZE;
|
|
315
|
+
var fontSize = Math.round(styles["font-size"] ? parseInt(styles["font-size"].replace("pt", ""), 10) : parseInt(td.style.fontSize || "".concat(ctxDefaultFontSize), 10));
|
|
189
316
|
cell.fs = fontSize;
|
|
190
317
|
cell.fc = td.style.color || styles.color;
|
|
191
318
|
var ht = td.style.textAlign || styles["text-align"] || "left";
|
|
@@ -196,12 +323,27 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
196
323
|
} else {
|
|
197
324
|
cell.ht = 1;
|
|
198
325
|
}
|
|
199
|
-
if (((
|
|
326
|
+
if (((_e = td === null || td === void 0 ? void 0 : td.style) === null || _e === void 0 ? void 0 : _e["overflow-wrap"]) === "anywhere") {
|
|
200
327
|
cell.tb = "2";
|
|
201
328
|
} else {
|
|
202
|
-
cell.tb = "
|
|
329
|
+
cell.tb = "1";
|
|
203
330
|
}
|
|
204
331
|
if ("mso-rotate" in styles) cell.rt = parseFloat(styles["mso-rotate"]);
|
|
332
|
+
var inlineSegments = getInlineStringSegmentsFromTd(td, cell, ctxDefaultFontSize);
|
|
333
|
+
var segmentsText = inlineSegments.map(function (s) {
|
|
334
|
+
var _a;
|
|
335
|
+
return (_a = s.v) !== null && _a !== void 0 ? _a : "";
|
|
336
|
+
}).join("");
|
|
337
|
+
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);
|
|
338
|
+
if (shouldUseInlineString) {
|
|
339
|
+
cell.v = normalizedText;
|
|
340
|
+
cell.m = normalizedText;
|
|
341
|
+
cell.ct = {
|
|
342
|
+
fa: "General",
|
|
343
|
+
t: "inlineStr",
|
|
344
|
+
s: inlineSegments
|
|
345
|
+
};
|
|
346
|
+
}
|
|
205
347
|
var rowspan = parseInt(td.getAttribute("rowspan") || "1", 10);
|
|
206
348
|
var colspan = parseInt(td.getAttribute("colspan") || "1", 10);
|
|
207
349
|
if (Number.isNaN(rowspan)) rowspan = 1;
|
|
@@ -215,7 +357,7 @@ var buildCellFromTd = function buildCellFromTd(td, classStyles, ctx) {
|
|
|
215
357
|
};
|
|
216
358
|
function handlePastedTable(ctx, html, pasteHandler) {
|
|
217
359
|
var _a;
|
|
218
|
-
if (
|
|
360
|
+
if (!/<table[\s/>]/i.test(html)) return;
|
|
219
361
|
var containerDiv = document.createElement("div");
|
|
220
362
|
containerDiv.innerHTML = html;
|
|
221
363
|
var tableColGropup = containerDiv.querySelectorAll("colgroup");
|
|
@@ -285,10 +427,17 @@ function handlePastedTable(ctx, html, pasteHandler) {
|
|
|
285
427
|
cell = _a.cell,
|
|
286
428
|
rowspan = _a.rowspan,
|
|
287
429
|
colspan = _a.colspan,
|
|
288
|
-
hyperlink = _a.hyperlink
|
|
430
|
+
hyperlink = _a.hyperlink,
|
|
431
|
+
srcRow = _a.srcRow,
|
|
432
|
+
srcCol = _a.srcCol;
|
|
289
433
|
var anchorCol = ctx.luckysheet_select_save[0].column[0];
|
|
290
434
|
var absoluteRow = anchorRow + localRowIndex;
|
|
291
435
|
var absoluteCol = anchorCol + localColIndex;
|
|
436
|
+
if (cell.f && srcRow != null && srcCol != null) {
|
|
437
|
+
try {
|
|
438
|
+
cell.f = (0, _paste.adjustFormulaForPaste)(cell.f, srcCol, srcRow, absoluteCol, absoluteRow);
|
|
439
|
+
} catch (_b) {}
|
|
440
|
+
}
|
|
292
441
|
pastedMatrix[localRowIndex][localColIndex] = cell;
|
|
293
442
|
if (hyperlink) {
|
|
294
443
|
(0, _modules.saveHyperlink)(ctx, absoluteRow, absoluteCol, hyperlink.href, "webpage", hyperlink.display);
|
package/lib/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;
|