@fileverse-dev/fortune-core 1.0.77 → 1.0.79

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.
@@ -1,3 +1,4 @@
1
1
  import { Context } from "../context";
2
+ export declare function parseAsLinkIfUrl(txtdata: string, ctx: Context): void;
2
3
  export declare function handlePaste(ctx: Context, e: ClipboardEvent): void;
3
4
  export declare function handlePasteByClick(ctx: Context, clipboardData: string, triggerType?: string): void;
@@ -990,8 +990,20 @@ function handleFormulaStringPaste(ctx, formulaStr) {
990
990
  afterUpdateCell(r, c, null, cellTemp);
991
991
  }
992
992
  }
993
+ export function parseAsLinkIfUrl(txtdata, ctx) {
994
+ var _a, _b, _c, _d, _e, _f, _g;
995
+ var urlRegex = /^(https?:\/\/[^\s]+)/;
996
+ if (urlRegex.test(txtdata)) {
997
+ var last = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
998
+ if (last) {
999
+ var rowIndex = (_d = (_b = last.row_focus) !== null && _b !== void 0 ? _b : (_c = last.row) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : 0;
1000
+ var colIndex = (_g = (_e = last.column_focus) !== null && _e !== void 0 ? _e : (_f = last.column) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : 0;
1001
+ saveHyperlink(ctx, rowIndex, colIndex, txtdata, "webpage", txtdata);
1002
+ }
1003
+ }
1004
+ }
993
1005
  export function handlePaste(ctx, e) {
994
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
1006
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
995
1007
  var allowEdit = isAllowEdit(ctx);
996
1008
  if (!allowEdit) return;
997
1009
  if (selectionCache.isPasteAction) {
@@ -1002,6 +1014,10 @@ export function handlePaste(ctx, e) {
1002
1014
  clipboardData = window.clipboardData;
1003
1015
  }
1004
1016
  if (!clipboardData) return;
1017
+ var text = clipboardData.getData("text/plain");
1018
+ if (text) {
1019
+ parseAsLinkIfUrl(text, ctx);
1020
+ }
1005
1021
  var txtdata = clipboardData.getData("text/html") || clipboardData.getData("text/plain");
1006
1022
  var isEqual = true;
1007
1023
  if (txtdata.indexOf("fortune-copy-action-table") > -1 && ((_a = ctx.luckysheet_copy_save) === null || _a === void 0 ? void 0 : _a.copyRange) != null && ctx.luckysheet_copy_save.copyRange.length > 0) {
@@ -1356,15 +1372,7 @@ export function handlePaste(ctx, e) {
1356
1372
  var text = clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.getData("text/plain");
1357
1373
  if (text) {
1358
1374
  document.execCommand("insertText", false, text);
1359
- var urlRegex = /^(https?:\/\/[^\s]+)/;
1360
- if (urlRegex.test(text)) {
1361
- var last = (_y = ctx.luckysheet_select_save) === null || _y === void 0 ? void 0 : _y[ctx.luckysheet_select_save.length - 1];
1362
- if (last) {
1363
- var rowIndex = (_1 = (_z = last.row_focus) !== null && _z !== void 0 ? _z : (_0 = last.row) === null || _0 === void 0 ? void 0 : _0[0]) !== null && _1 !== void 0 ? _1 : 0;
1364
- var colIndex = (_4 = (_2 = last.column_focus) !== null && _2 !== void 0 ? _2 : (_3 = last.column) === null || _3 === void 0 ? void 0 : _3[0]) !== null && _4 !== void 0 ? _4 : 0;
1365
- saveHyperlink(ctx, rowIndex, colIndex, text, "webpage", text);
1366
- }
1367
- }
1375
+ parseAsLinkIfUrl(text, ctx);
1368
1376
  }
1369
1377
  }
1370
1378
  }
@@ -1193,10 +1193,18 @@ export function createRangeHightlight(ctx, inputInnerHtmlStr, ignoreRangeIndex)
1193
1193
  ctx.formulaRangeHighlight = formulaRanges;
1194
1194
  }
1195
1195
  export function setCaretPosition(ctx, textDom, children, pos) {
1196
+ var _a, _b;
1196
1197
  try {
1197
1198
  var el = textDom;
1198
1199
  var range = document.createRange();
1199
1200
  var sel = window.getSelection();
1201
+ var mainSpan = document.querySelector('.luckysheet-formula-text-string');
1202
+ var textContent = ((_b = (_a = mainSpan === null || mainSpan === void 0 ? void 0 : mainSpan.firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.trim()) || '';
1203
+ var innerSpan = mainSpan === null || mainSpan === void 0 ? void 0 : mainSpan.querySelector('.fortune-formula-functionrange-cell');
1204
+ if (innerSpan && mainSpan) {
1205
+ textContent += innerSpan.textContent;
1206
+ el.innerHTML = textContent;
1207
+ }
1200
1208
  range.setStart(el.childNodes[children], pos);
1201
1209
  range.collapse(true);
1202
1210
  sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
@@ -1,3 +1,4 @@
1
1
  import { Context } from "../context";
2
+ export declare function parseAsLinkIfUrl(txtdata: string, ctx: Context): void;
2
3
  export declare function handlePaste(ctx: Context, e: ClipboardEvent): void;
3
4
  export declare function handlePasteByClick(ctx: Context, clipboardData: string, triggerType?: string): void;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.handlePaste = handlePaste;
7
7
  exports.handlePasteByClick = handlePasteByClick;
8
+ exports.parseAsLinkIfUrl = parseAsLinkIfUrl;
8
9
  var _lodash = _interopRequireDefault(require("lodash"));
9
10
  var _context = require("../context");
10
11
  var _locale = require("../locale");
@@ -998,8 +999,20 @@ function handleFormulaStringPaste(ctx, formulaStr) {
998
999
  afterUpdateCell(r, c, null, cellTemp);
999
1000
  }
1000
1001
  }
1002
+ function parseAsLinkIfUrl(txtdata, ctx) {
1003
+ var _a, _b, _c, _d, _e, _f, _g;
1004
+ var urlRegex = /^(https?:\/\/[^\s]+)/;
1005
+ if (urlRegex.test(txtdata)) {
1006
+ var last = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[ctx.luckysheet_select_save.length - 1];
1007
+ if (last) {
1008
+ var rowIndex = (_d = (_b = last.row_focus) !== null && _b !== void 0 ? _b : (_c = last.row) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : 0;
1009
+ var colIndex = (_g = (_e = last.column_focus) !== null && _e !== void 0 ? _e : (_f = last.column) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : 0;
1010
+ (0, _modules.saveHyperlink)(ctx, rowIndex, colIndex, txtdata, "webpage", txtdata);
1011
+ }
1012
+ }
1013
+ }
1001
1014
  function handlePaste(ctx, e) {
1002
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
1015
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
1003
1016
  var allowEdit = (0, _utils.isAllowEdit)(ctx);
1004
1017
  if (!allowEdit) return;
1005
1018
  if (_selection.selectionCache.isPasteAction) {
@@ -1010,6 +1023,10 @@ function handlePaste(ctx, e) {
1010
1023
  clipboardData = window.clipboardData;
1011
1024
  }
1012
1025
  if (!clipboardData) return;
1026
+ var text = clipboardData.getData("text/plain");
1027
+ if (text) {
1028
+ parseAsLinkIfUrl(text, ctx);
1029
+ }
1013
1030
  var txtdata = clipboardData.getData("text/html") || clipboardData.getData("text/plain");
1014
1031
  var isEqual = true;
1015
1032
  if (txtdata.indexOf("fortune-copy-action-table") > -1 && ((_a = ctx.luckysheet_copy_save) === null || _a === void 0 ? void 0 : _a.copyRange) != null && ctx.luckysheet_copy_save.copyRange.length > 0) {
@@ -1364,15 +1381,7 @@ function handlePaste(ctx, e) {
1364
1381
  var text = clipboardData === null || clipboardData === void 0 ? void 0 : clipboardData.getData("text/plain");
1365
1382
  if (text) {
1366
1383
  document.execCommand("insertText", false, text);
1367
- var urlRegex = /^(https?:\/\/[^\s]+)/;
1368
- if (urlRegex.test(text)) {
1369
- var last = (_y = ctx.luckysheet_select_save) === null || _y === void 0 ? void 0 : _y[ctx.luckysheet_select_save.length - 1];
1370
- if (last) {
1371
- var rowIndex = (_1 = (_z = last.row_focus) !== null && _z !== void 0 ? _z : (_0 = last.row) === null || _0 === void 0 ? void 0 : _0[0]) !== null && _1 !== void 0 ? _1 : 0;
1372
- var colIndex = (_4 = (_2 = last.column_focus) !== null && _2 !== void 0 ? _2 : (_3 = last.column) === null || _3 === void 0 ? void 0 : _3[0]) !== null && _4 !== void 0 ? _4 : 0;
1373
- (0, _modules.saveHyperlink)(ctx, rowIndex, colIndex, text, "webpage", text);
1374
- }
1375
- }
1384
+ parseAsLinkIfUrl(text, ctx);
1376
1385
  }
1377
1386
  }
1378
1387
  }
@@ -1222,10 +1222,18 @@ function createRangeHightlight(ctx, inputInnerHtmlStr, ignoreRangeIndex) {
1222
1222
  ctx.formulaRangeHighlight = formulaRanges;
1223
1223
  }
1224
1224
  function setCaretPosition(ctx, textDom, children, pos) {
1225
+ var _a, _b;
1225
1226
  try {
1226
1227
  var el = textDom;
1227
1228
  var range = document.createRange();
1228
1229
  var sel = window.getSelection();
1230
+ var mainSpan = document.querySelector('.luckysheet-formula-text-string');
1231
+ var textContent = ((_b = (_a = mainSpan === null || mainSpan === void 0 ? void 0 : mainSpan.firstChild) === null || _a === void 0 ? void 0 : _a.nodeValue) === null || _b === void 0 ? void 0 : _b.trim()) || '';
1232
+ var innerSpan = mainSpan === null || mainSpan === void 0 ? void 0 : mainSpan.querySelector('.fortune-formula-functionrange-cell');
1233
+ if (innerSpan && mainSpan) {
1234
+ textContent += innerSpan.textContent;
1235
+ el.innerHTML = textContent;
1236
+ }
1229
1237
  range.setStart(el.childNodes[children], pos);
1230
1238
  range.collapse(true);
1231
1239
  sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-core",
3
- "version": "1.0.77",
3
+ "version": "1.0.79",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "lib/index.d.ts",