@leankylin-sheet/react 6.0.0 → 6.0.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.
@@ -93,6 +93,7 @@ export declare function generateAPIs(context: Context, setContext: (recipe: (ctx
93
93
  hyperlink?: Record<string, {
94
94
  linkType: string;
95
95
  linkAddress: string;
96
+ payload?: Record<string, any> | undefined;
96
97
  }> | undefined;
97
98
  dynamicArray_compute?: any;
98
99
  dynamicArray?: any[] | undefined;
@@ -101,6 +101,7 @@ declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalPro
101
101
  hyperlink?: Record<string, {
102
102
  linkType: string;
103
103
  linkAddress: string;
104
+ payload?: Record<string, any> | undefined;
104
105
  }> | undefined;
105
106
  dynamicArray_compute?: any;
106
107
  dynamicArray?: any[] | undefined;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defaultContext, defaultSettings, getSheetIndex, colLocationByIndex, fixPositionOnFrozenCells, colLocation, getFlowdata, isAllowEdit, handleColumnHeaderMouseDown, handleColSizeHandleMouseDown, handleColFreezeHandleMouseDown, handleContextMenu, selectTitlesMap, selectTitlesRange, fixColumnStyleOverflowInFreeze, rowLocationByIndex, rowLocation, handleRowHeaderMouseDown, handleRowSizeHandleMouseDown, handleRowFreezeHandleMouseDown, fixRowStyleOverflowInFreeze, functionHTMLGenerate, locale, getCellValue, createRangeHightlight, isInlineStringCell, getInlineStringHTML, valueShowEs, escapeHTMLTag, escapeScriptTag, isShowHidenCR, cancelNormalSelected, moveHighlightCell, updateCell, israngeseleciton, handleFormulaInput, onSearchDialogMoveStart, replaceAll, replace, searchAll, searchNext, changeSheet, normalizeSelection, scrollToHighlightCell, chatatABC, isLinkValid, getRangetxt, goToLink, replaceHtml, removeHyperlink, onRangeSelectionModalMoveStart, saveHyperlink, createFilterOptions, onImageMoveStart, onImageResizeStart, showComments, setEditingComment, onCommentBoxMoveStart, onCommentBoxResizeStart, confirmMessage, getRangeByTxt, getDropdownList, setCellValue, setConditionRules, mergeBorder, setDropcownValue, handleCellAreaMouseDown, handleCellAreaMouseMove, handleCellAreaDragOver, handleCellDrop, handleCellAreaDoubleClick, selectAll, showLinkCard, getCellRowColumn, getCellHyperlink, handleOverlayMouseMove, handleOverlayMouseUp, handleKeydownForZoom, handleOverlayTouchStart, handleOverlayTouchMove, handleOverlayTouchEnd, onCellsMoveStart, createDropCellRange, handleDropCellDoubleClick, updateContextWithSheetData, updateContextWithCanvas, initFreeze, Canvas, handleGlobalWheel, setCaretPosition, getDataArr, updateMoreCell, getRegStr, getOptionValue, getSelectRange, applyLocation, updateItem, update, normalizedCellAttr, updateFormat, handleTextSize, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, showImgChooser, insertImage, editComment, deleteComment, showHideComment, showHideAllComments, newComment, handleSum, autoSelectionFormula, handleMerge, handleBorder, handleFreeze, handleSort, createFilter, clearFilter, toolbarItemSelectedFunc, toolbarItemClickHandler, handleTextColor, handleTextBackground, getDataBySelectionNoCopy, getInlineStringNoStyle, rangeHightlightselected, editSheetName, setNextSheet, MAX_ZOOM_RATIO, MIN_ZOOM_RATIO, addSheet, indexToColumnChar, sortSelection, handleCopy, insertRowCol, deleteRowCol, hideSelected, showSelected, api, removeActiveImage, deleteSelectedCellText, jfrefreshgrid, handleLink, deleteSheet, opToPatch, orderbydatafiler, getFilterColumnValues, getFilterColumnColors, saveFilter, cancelActiveImgItem, patchToOp, filterPatch, inverseRowColOptions, ensureSheetIndex, initSheetIndex, handleGlobalKeyDown, handlePasteByLeanklin, groupValuesRefresh } from '@leankylin-sheet/core';
1
+ import { defaultContext, defaultSettings, getSheetIndex, colLocationByIndex, fixPositionOnFrozenCells, colLocation, getFlowdata, isAllowEdit, handleColumnHeaderMouseDown, handleColSizeHandleMouseDown, handleColFreezeHandleMouseDown, handleContextMenu, selectTitlesMap, selectTitlesRange, fixColumnStyleOverflowInFreeze, rowLocationByIndex, rowLocation, handleRowHeaderMouseDown, handleRowSizeHandleMouseDown, handleRowFreezeHandleMouseDown, fixRowStyleOverflowInFreeze, functionHTMLGenerate, locale, getCellValue, createRangeHightlight, isInlineStringCell, getInlineStringHTML, valueShowEs, escapeHTMLTag, escapeScriptTag, isShowHidenCR, cancelNormalSelected, moveHighlightCell, updateCell, israngeseleciton, handleFormulaInput, onSearchDialogMoveStart, replaceAll, replace, searchAll, searchNext, changeSheet, normalizeSelection, scrollToHighlightCell, chatatABC, getCellHyperlink, isLinkValid, getRangetxt, goToLink, replaceHtml, removeHyperlink, onRangeSelectionModalMoveStart, saveHyperlink, createFilterOptions, onImageMoveStart, onImageResizeStart, showComments, setEditingComment, onCommentBoxMoveStart, onCommentBoxResizeStart, confirmMessage, getRangeByTxt, getDropdownList, setCellValue, setConditionRules, mergeBorder, setDropcownValue, handleCellAreaMouseDown, handleCellAreaMouseMove, handleCellAreaDragOver, handleCellDrop, handleCellAreaDoubleClick, selectAll, showLinkCard, getCellRowColumn, handleOverlayMouseMove, handleOverlayMouseUp, handleKeydownForZoom, handleOverlayTouchStart, handleOverlayTouchMove, handleOverlayTouchEnd, onCellsMoveStart, createDropCellRange, handleDropCellDoubleClick, updateContextWithSheetData, updateContextWithCanvas, initFreeze, Canvas, handleGlobalWheel, setCaretPosition, getDataArr, updateMoreCell, getRegStr, getOptionValue, getSelectRange, applyLocation, updateItem, update, normalizedCellAttr, updateFormat, handleTextSize, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, showImgChooser, insertImage, editComment, deleteComment, showHideComment, showHideAllComments, newComment, handleSum, autoSelectionFormula, handleMerge, handleBorder, handleFreeze, handleSort, createFilter, clearFilter, toolbarItemSelectedFunc, toolbarItemClickHandler, handleTextColor, handleTextBackground, getDataBySelectionNoCopy, getInlineStringNoStyle, rangeHightlightselected, editSheetName, setNextSheet, MAX_ZOOM_RATIO, MIN_ZOOM_RATIO, addSheet, indexToColumnChar, sortSelection, handleCopy, insertRowCol, deleteRowCol, hideSelected, showSelected, api, removeActiveImage, deleteSelectedCellText, jfrefreshgrid, handleLink, deleteSheet, opToPatch, orderbydatafiler, getFilterColumnValues, getFilterColumnColors, saveFilter, cancelActiveImgItem, patchToOp, filterPatch, inverseRowColOptions, ensureSheetIndex, initSheetIndex, handleGlobalKeyDown, handlePasteByLeanklin, groupValuesRefresh } from '@leankylin-sheet/core';
2
2
  import { useInViewport, useMemoizedFn, useThrottleFn } from 'ahooks';
3
3
  import React, { useContext, useRef, useState, useMemo, useCallback, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
4
4
  import produce, { applyPatches, enablePatches, produceWithPatches } from 'immer';
@@ -2263,7 +2263,7 @@ var LinkEditCard = function LinkEditCard(_ref) {
2263
2263
  c = _ref.c,
2264
2264
  rc = _ref.rc,
2265
2265
  originText = _ref.originText,
2266
- originType = _ref.originType,
2266
+ _originType = _ref.originType,
2267
2267
  originAddress = _ref.originAddress,
2268
2268
  isEditing = _ref.isEditing,
2269
2269
  position = _ref.position,
@@ -2271,7 +2271,8 @@ var LinkEditCard = function LinkEditCard(_ref) {
2271
2271
  var _useContext = useContext(WorkbookContext),
2272
2272
  context = _useContext.context,
2273
2273
  setContext = _useContext.setContext,
2274
- refs = _useContext.refs;
2274
+ refs = _useContext.refs,
2275
+ settings = _useContext.settings;
2275
2276
  var _useState = useState(originText),
2276
2277
  _useState2 = _slicedToArray(_useState, 2),
2277
2278
  linkText = _useState2[0],
@@ -2280,10 +2281,19 @@ var LinkEditCard = function LinkEditCard(_ref) {
2280
2281
  _useState4 = _slicedToArray(_useState3, 2),
2281
2282
  linkAddress = _useState4[0],
2282
2283
  setLinkAddress = _useState4[1];
2284
+ var originType = _originType || settings.detailLinkType || "webpage";
2283
2285
  var _useState5 = useState(originType),
2284
2286
  _useState6 = _slicedToArray(_useState5, 2),
2285
2287
  linkType = _useState6[0],
2286
2288
  setLinkType = _useState6[1];
2289
+ var _useState7 = useState(function () {
2290
+ var _origin$payload;
2291
+ var origin = getCellHyperlink(context, r, c);
2292
+ return (_origin$payload = origin === null || origin === void 0 ? void 0 : origin.payload) !== null && _origin$payload !== void 0 ? _origin$payload : {};
2293
+ }),
2294
+ _useState8 = _slicedToArray(_useState7, 2),
2295
+ customPayload = _useState8[0],
2296
+ setCustomPayload = _useState8[1];
2287
2297
  var _locale = locale(context),
2288
2298
  insertLink = _locale.insertLink,
2289
2299
  linkTypeList = _locale.linkTypeList,
@@ -2294,9 +2304,65 @@ var LinkEditCard = function LinkEditCard(_ref) {
2294
2304
  }]));
2295
2305
  var skipCellRangeSet = useRef(true);
2296
2306
  var isLinkAddressValid = isLinkValid(context, linkType, linkAddress);
2297
- var tooltip = /*#__PURE__*/React.createElement("div", {
2298
- className: "validation-input-tip"
2299
- }, isLinkAddressValid.tooltip);
2307
+ var mergedLinkTypeList = useMemo(function () {
2308
+ var _settings$customLinkT;
2309
+ var customs = (_settings$customLinkT = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT !== void 0 ? _settings$customLinkT : [];
2310
+ if (customs.length === 0) return linkTypeList;
2311
+ var builtinTypes = new Set(linkTypeList.map(function (it) {
2312
+ return it.value;
2313
+ }));
2314
+ var extra = customs.filter(function (it) {
2315
+ return it.type && !builtinTypes.has(it.type);
2316
+ }).map(function (it) {
2317
+ return {
2318
+ text: it.text,
2319
+ value: it.type
2320
+ };
2321
+ });
2322
+ return [].concat(_toConsumableArray(extra), _toConsumableArray(linkTypeList));
2323
+ }, [settings === null || settings === void 0 ? void 0 : settings.customLinkTypes, linkTypeList]);
2324
+ var customLinkTypeMap = useMemo(function () {
2325
+ var _settings$customLinkT2;
2326
+ var m = {};
2327
+ ((_settings$customLinkT2 = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT2 !== void 0 ? _settings$customLinkT2 : []).forEach(function (it) {
2328
+ if (it.type) m[it.type] = it;
2329
+ });
2330
+ return m;
2331
+ }, [settings === null || settings === void 0 ? void 0 : settings.customLinkTypes]);
2332
+ var currentCustomConfig = customLinkTypeMap[linkType];
2333
+ var isCustomTypeValid = useMemo(function () {
2334
+ if (!currentCustomConfig) return true;
2335
+ if (!currentCustomConfig.onSave) return true;
2336
+ var next = currentCustomConfig.onSave({
2337
+ linkText: linkText,
2338
+ linkAddress: linkAddress,
2339
+ position: {
2340
+ r: r,
2341
+ c: c
2342
+ },
2343
+ origin: function () {
2344
+ var o = getCellHyperlink(context, r, c);
2345
+ return o ? {
2346
+ linkType: o.linkType,
2347
+ linkAddress: o.linkAddress,
2348
+ payload: o.payload
2349
+ } : undefined;
2350
+ }()
2351
+ });
2352
+ return next !== undefined;
2353
+ }, [currentCustomConfig, linkText, linkAddress, r, c, context]);
2354
+ var canSubmit = !currentCustomConfig || isCustomTypeValid ? isLinkAddressValid.isValid : false;
2355
+ var tooltip = function () {
2356
+ var text;
2357
+ if (currentCustomConfig) {
2358
+ text = isCustomTypeValid ? "" : insertLink.tooltipInfo1 || "";
2359
+ } else {
2360
+ text = isLinkAddressValid.tooltip;
2361
+ }
2362
+ return /*#__PURE__*/React.createElement("div", {
2363
+ className: "validation-input-tip"
2364
+ }, text);
2365
+ }();
2300
2366
  var hideLinkCard = useCallback(function () {
2301
2367
  _.set(refs.globalCache, "linkCard.mouseEnter", false);
2302
2368
  setContext(function (draftCtx) {
@@ -2358,10 +2424,13 @@ var LinkEditCard = function LinkEditCard(_ref) {
2358
2424
  }));
2359
2425
  }, []);
2360
2426
  useLayoutEffect(function () {
2427
+ var _origin$payload2;
2361
2428
  setLinkAddress(originAddress);
2362
2429
  setLinkText(originText);
2363
2430
  setLinkType(originType);
2364
- }, [rc, originAddress, originText, originType]);
2431
+ var origin = getCellHyperlink(context, r, c);
2432
+ setCustomPayload((_origin$payload2 = origin === null || origin === void 0 ? void 0 : origin.payload) !== null && _origin$payload2 !== void 0 ? _origin$payload2 : {});
2433
+ }, [rc, originAddress, originText, originType, r, c, context]);
2365
2434
  useLayoutEffect(function () {
2366
2435
  if (selectingCellRange) {
2367
2436
  skipCellRangeSet.current = true;
@@ -2380,6 +2449,7 @@ var LinkEditCard = function LinkEditCard(_ref) {
2380
2449
  }
2381
2450
  }, [context, selectingCellRange]);
2382
2451
  if (!isEditing) {
2452
+ var toolbarCustomConfig = customLinkTypeMap[originType];
2383
2453
  return /*#__PURE__*/React.createElement("div", _objectSpread2(_objectSpread2({}, containerEvent), {}, {
2384
2454
  onKeyDown: function onKeyDown(e) {
2385
2455
  e.stopPropagation();
@@ -2391,16 +2461,35 @@ var LinkEditCard = function LinkEditCard(_ref) {
2391
2461
  }
2392
2462
  }), /*#__PURE__*/React.createElement("div", {
2393
2463
  className: "link-content",
2394
- onClick: function onClick() {
2464
+ onClick: function onClick(reactEvent) {
2465
+ var _getCellHyperlink, _toolbarCustomConfig$, _settings$hooks, _settings$hooks$onHyp;
2466
+ var payload = (_getCellHyperlink = getCellHyperlink(context, r, c)) === null || _getCellHyperlink === void 0 ? void 0 : _getCellHyperlink.payload;
2467
+ var clickInfo = {
2468
+ linkType: originType,
2469
+ linkAddress: originAddress,
2470
+ payload: payload,
2471
+ position: {
2472
+ r: r,
2473
+ c: c,
2474
+ sheetId: context.currentSheetId
2475
+ },
2476
+ event: reactEvent
2477
+ };
2478
+ var userResult = toolbarCustomConfig === null || toolbarCustomConfig === void 0 ? void 0 : (_toolbarCustomConfig$ = toolbarCustomConfig.onClick) === null || _toolbarCustomConfig$ === void 0 ? void 0 : _toolbarCustomConfig$.call(toolbarCustomConfig, clickInfo);
2479
+ settings === null || settings === void 0 ? void 0 : (_settings$hooks = settings.hooks) === null || _settings$hooks === void 0 ? void 0 : (_settings$hooks$onHyp = _settings$hooks.onHyperlinkClick) === null || _settings$hooks$onHyp === void 0 ? void 0 : _settings$hooks$onHyp.call(_settings$hooks, clickInfo);
2480
+ if (userResult === false) {
2481
+ hideLinkCard();
2482
+ return;
2483
+ }
2395
2484
  setContext(function (draftCtx) {
2396
- return goToLink(draftCtx, r, c, linkType, linkAddress, refs.scrollbarX.current, refs.scrollbarY.current);
2485
+ return goToLink(draftCtx, r, c, originType, originAddress, refs.scrollbarX.current, refs.scrollbarY.current);
2397
2486
  });
2398
2487
  }
2399
- }, linkType === "webpage" ? insertLink.openLink : replaceHtml(insertLink.goTo, {
2400
- linkAddress: linkAddress
2488
+ }, originType === "webpage" ? insertLink.openLink : replaceHtml(insertLink.goTo, {
2489
+ linkAddress: originAddress
2401
2490
  })), context.allowEdit === true && /*#__PURE__*/React.createElement("div", {
2402
2491
  className: "divider"
2403
- }), context.allowEdit === true && linkType === "webpage" && renderToolbarButton("copy", function () {
2492
+ }), context.allowEdit === true && originType === "webpage" && renderToolbarButton("copy", function () {
2404
2493
  navigator.clipboard.writeText(originAddress);
2405
2494
  hideLinkCard();
2406
2495
  }), context.allowEdit === true && renderToolbarButton("pencil", function () {
@@ -2479,18 +2568,23 @@ var LinkEditCard = function LinkEditCard(_ref) {
2479
2568
  className: "leankylin-link-modify-select",
2480
2569
  value: linkType,
2481
2570
  onChange: function onChange(e) {
2482
- if (e.target.value === "sheet") {
2571
+ var next = e.target.value;
2572
+ var nextCustomConfig = customLinkTypeMap[next];
2573
+ if (next === "sheet") {
2483
2574
  if (!linkText) {
2484
2575
  setLinkText(context.luckysheetfile[0].name);
2485
2576
  }
2486
2577
  setLinkAddress(context.luckysheetfile[0].name);
2578
+ } else if (nextCustomConfig) {
2579
+ setLinkAddress("");
2580
+ setCustomPayload({});
2487
2581
  } else {
2488
2582
  setLinkAddress("");
2489
2583
  }
2490
- if (e.target.value === "cellrange") setRangeModalVisible(true);
2491
- setLinkType(e.target.value);
2584
+ if (next === "cellrange") setRangeModalVisible(true);
2585
+ setLinkType(next);
2492
2586
  }
2493
- }, linkTypeList.map(function (type) {
2587
+ }, mergedLinkTypeList.map(function (type) {
2494
2588
  return /*#__PURE__*/React.createElement("option", {
2495
2589
  key: type.value,
2496
2590
  value: type.value
@@ -2536,11 +2630,63 @@ var LinkEditCard = function LinkEditCard(_ref) {
2536
2630
  key: sheet.id,
2537
2631
  value: sheet.name
2538
2632
  }, sheet.name);
2633
+ })), tooltip)), currentCustomConfig && ( /*#__PURE__*/React.createElement(React.Fragment, null, currentCustomConfig.render ? currentCustomConfig.render({
2634
+ value: linkAddress,
2635
+ position: {
2636
+ r: r,
2637
+ c: c
2638
+ },
2639
+ onChange: function onChange(v) {
2640
+ return setLinkAddress(v);
2641
+ },
2642
+ setPayload: function setPayload(next) {
2643
+ setCustomPayload(function (prev) {
2644
+ return typeof next === "function" ? next(prev) : next;
2645
+ });
2646
+ },
2647
+ payload: customPayload,
2648
+ ctx: {
2649
+ context: context,
2650
+ setContext: setContext,
2651
+ settings: settings
2652
+ }
2653
+ }) : ( /*#__PURE__*/React.createElement("input", {
2654
+ className: "leankylin-link-modify-input ".concat(canSubmit ? "" : "error-input"),
2655
+ spellCheck: "false",
2656
+ value: linkAddress,
2657
+ onChange: function onChange(e) {
2658
+ return setLinkAddress(e.target.value);
2659
+ }
2539
2660
  })), tooltip))), /*#__PURE__*/React.createElement("div", {
2540
2661
  className: "modal-footer"
2541
2662
  }, renderBottomButton(function () {
2542
- if (!isLinkAddressValid.isValid) return;
2663
+ if (!canSubmit) return;
2543
2664
  _.set(refs.globalCache, "linkCard.mouseEnter", false);
2665
+ if (currentCustomConfig === null || currentCustomConfig === void 0 ? void 0 : currentCustomConfig.onSave) {
2666
+ var origin = function () {
2667
+ var o = getCellHyperlink(context, r, c);
2668
+ return o ? {
2669
+ linkType: o.linkType,
2670
+ linkAddress: o.linkAddress,
2671
+ payload: o.payload
2672
+ } : undefined;
2673
+ }();
2674
+ var saved = currentCustomConfig.onSave({
2675
+ linkText: linkText,
2676
+ linkAddress: linkAddress,
2677
+ position: {
2678
+ r: r,
2679
+ c: c
2680
+ },
2681
+ origin: origin
2682
+ });
2683
+ if (!saved) return;
2684
+ setContext(function (draftCtx) {
2685
+ var _saved$payload;
2686
+ return saveHyperlink(draftCtx, r, c, linkText || saved.linkAddress, saved.linkType, saved.linkAddress, _objectSpread2(_objectSpread2({}, customPayload), (_saved$payload = saved.payload) !== null && _saved$payload !== void 0 ? _saved$payload : {}));
2687
+ });
2688
+ return;
2689
+ }
2544
2690
  setContext(function (draftCtx) {
2545
2691
  return saveHyperlink(draftCtx, r, c, linkText, linkType, linkAddress);
2546
2692
  });
@@ -4417,10 +4563,30 @@ var SheetOverlay = function SheetOverlay() {
4417
4563
  if (link == null) {
4418
4564
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false);
4419
4565
  } else {
4566
+ var _settings$customLinkT, _customConfig$onHover, _settings$hooks, _settings$hooks$onHyp;
4420
4567
  showLinkCard(ctx, rc.r, rc.c, false);
4421
4568
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false, true);
4569
+ var payload = link.payload;
4570
+ var customConfigMap = ((_settings$customLinkT = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT !== void 0 ? _settings$customLinkT : []).reduce(function (acc, it) {
4571
+ if (it.type) acc[it.type] = it;
4572
+ return acc;
4573
+ }, {});
4574
+ var customConfig = customConfigMap[link.linkType];
4575
+ var hoverInfo = {
4576
+ linkType: link.linkType,
4577
+ linkAddress: link.linkAddress,
4578
+ payload: payload,
4579
+ position: {
4580
+ r: rc.r,
4581
+ c: rc.c,
4582
+ sheetId: ctx.currentSheetId
4583
+ },
4584
+ event: e
4585
+ };
4586
+ customConfig === null || customConfig === void 0 ? void 0 : (_customConfig$onHover = customConfig.onHover) === null || _customConfig$onHover === void 0 ? void 0 : _customConfig$onHover.call(customConfig, hoverInfo);
4587
+ settings === null || settings === void 0 ? void 0 : (_settings$hooks = settings.hooks) === null || _settings$hooks === void 0 ? void 0 : (_settings$hooks$onHyp = _settings$hooks.onHyperlinkHover) === null || _settings$hooks$onHyp === void 0 ? void 0 : _settings$hooks$onHyp.call(_settings$hooks, hoverInfo);
4422
4588
  }
4423
- }, [debouncedShowLinkCard]);
4589
+ }, [debouncedShowLinkCard, settings]);
4424
4590
  var lastHoverCellRef = useRef(null);
4425
4591
  var onMouseMove = useCallback(function (nativeEvent) {
4426
4592
  var _gc$commentBox, _gc$commentBox2, _gc$searchDialog, _gc$linkCard;
package/dist/index.js CHANGED
@@ -2273,7 +2273,7 @@ var LinkEditCard = function LinkEditCard(_ref) {
2273
2273
  c = _ref.c,
2274
2274
  rc = _ref.rc,
2275
2275
  originText = _ref.originText,
2276
- originType = _ref.originType,
2276
+ _originType = _ref.originType,
2277
2277
  originAddress = _ref.originAddress,
2278
2278
  isEditing = _ref.isEditing,
2279
2279
  position = _ref.position,
@@ -2281,7 +2281,8 @@ var LinkEditCard = function LinkEditCard(_ref) {
2281
2281
  var _useContext = React.useContext(WorkbookContext),
2282
2282
  context = _useContext.context,
2283
2283
  setContext = _useContext.setContext,
2284
- refs = _useContext.refs;
2284
+ refs = _useContext.refs,
2285
+ settings = _useContext.settings;
2285
2286
  var _useState = React.useState(originText),
2286
2287
  _useState2 = _slicedToArray(_useState, 2),
2287
2288
  linkText = _useState2[0],
@@ -2290,10 +2291,19 @@ var LinkEditCard = function LinkEditCard(_ref) {
2290
2291
  _useState4 = _slicedToArray(_useState3, 2),
2291
2292
  linkAddress = _useState4[0],
2292
2293
  setLinkAddress = _useState4[1];
2294
+ var originType = _originType || settings.detailLinkType || "webpage";
2293
2295
  var _useState5 = React.useState(originType),
2294
2296
  _useState6 = _slicedToArray(_useState5, 2),
2295
2297
  linkType = _useState6[0],
2296
2298
  setLinkType = _useState6[1];
2299
+ var _useState7 = React.useState(function () {
2300
+ var _origin$payload;
2301
+ var origin = core.getCellHyperlink(context, r, c);
2302
+ return (_origin$payload = origin === null || origin === void 0 ? void 0 : origin.payload) !== null && _origin$payload !== void 0 ? _origin$payload : {};
2303
+ }),
2304
+ _useState8 = _slicedToArray(_useState7, 2),
2305
+ customPayload = _useState8[0],
2306
+ setCustomPayload = _useState8[1];
2297
2307
  var _locale = core.locale(context),
2298
2308
  insertLink = _locale.insertLink,
2299
2309
  linkTypeList = _locale.linkTypeList,
@@ -2304,9 +2314,65 @@ var LinkEditCard = function LinkEditCard(_ref) {
2304
2314
  }]));
2305
2315
  var skipCellRangeSet = React.useRef(true);
2306
2316
  var isLinkAddressValid = core.isLinkValid(context, linkType, linkAddress);
2307
- var tooltip = /*#__PURE__*/React__default['default'].createElement("div", {
2308
- className: "validation-input-tip"
2309
- }, isLinkAddressValid.tooltip);
2317
+ var mergedLinkTypeList = React.useMemo(function () {
2318
+ var _settings$customLinkT;
2319
+ var customs = (_settings$customLinkT = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT !== void 0 ? _settings$customLinkT : [];
2320
+ if (customs.length === 0) return linkTypeList;
2321
+ var builtinTypes = new Set(linkTypeList.map(function (it) {
2322
+ return it.value;
2323
+ }));
2324
+ var extra = customs.filter(function (it) {
2325
+ return it.type && !builtinTypes.has(it.type);
2326
+ }).map(function (it) {
2327
+ return {
2328
+ text: it.text,
2329
+ value: it.type
2330
+ };
2331
+ });
2332
+ return [].concat(_toConsumableArray(extra), _toConsumableArray(linkTypeList));
2333
+ }, [settings === null || settings === void 0 ? void 0 : settings.customLinkTypes, linkTypeList]);
2334
+ var customLinkTypeMap = React.useMemo(function () {
2335
+ var _settings$customLinkT2;
2336
+ var m = {};
2337
+ ((_settings$customLinkT2 = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT2 !== void 0 ? _settings$customLinkT2 : []).forEach(function (it) {
2338
+ if (it.type) m[it.type] = it;
2339
+ });
2340
+ return m;
2341
+ }, [settings === null || settings === void 0 ? void 0 : settings.customLinkTypes]);
2342
+ var currentCustomConfig = customLinkTypeMap[linkType];
2343
+ var isCustomTypeValid = React.useMemo(function () {
2344
+ if (!currentCustomConfig) return true;
2345
+ if (!currentCustomConfig.onSave) return true;
2346
+ var next = currentCustomConfig.onSave({
2347
+ linkText: linkText,
2348
+ linkAddress: linkAddress,
2349
+ position: {
2350
+ r: r,
2351
+ c: c
2352
+ },
2353
+ origin: function () {
2354
+ var o = core.getCellHyperlink(context, r, c);
2355
+ return o ? {
2356
+ linkType: o.linkType,
2357
+ linkAddress: o.linkAddress,
2358
+ payload: o.payload
2359
+ } : undefined;
2360
+ }()
2361
+ });
2362
+ return next !== undefined;
2363
+ }, [currentCustomConfig, linkText, linkAddress, r, c, context]);
2364
+ var canSubmit = !currentCustomConfig || isCustomTypeValid ? isLinkAddressValid.isValid : false;
2365
+ var tooltip = function () {
2366
+ var text;
2367
+ if (currentCustomConfig) {
2368
+ text = isCustomTypeValid ? "" : insertLink.tooltipInfo1 || "";
2369
+ } else {
2370
+ text = isLinkAddressValid.tooltip;
2371
+ }
2372
+ return /*#__PURE__*/React__default['default'].createElement("div", {
2373
+ className: "validation-input-tip"
2374
+ }, text);
2375
+ }();
2310
2376
  var hideLinkCard = React.useCallback(function () {
2311
2377
  ___default['default'].set(refs.globalCache, "linkCard.mouseEnter", false);
2312
2378
  setContext(function (draftCtx) {
@@ -2368,10 +2434,13 @@ var LinkEditCard = function LinkEditCard(_ref) {
2368
2434
  }));
2369
2435
  }, []);
2370
2436
  React.useLayoutEffect(function () {
2437
+ var _origin$payload2;
2371
2438
  setLinkAddress(originAddress);
2372
2439
  setLinkText(originText);
2373
2440
  setLinkType(originType);
2374
- }, [rc, originAddress, originText, originType]);
2441
+ var origin = core.getCellHyperlink(context, r, c);
2442
+ setCustomPayload((_origin$payload2 = origin === null || origin === void 0 ? void 0 : origin.payload) !== null && _origin$payload2 !== void 0 ? _origin$payload2 : {});
2443
+ }, [rc, originAddress, originText, originType, r, c, context]);
2375
2444
  React.useLayoutEffect(function () {
2376
2445
  if (selectingCellRange) {
2377
2446
  skipCellRangeSet.current = true;
@@ -2390,6 +2459,7 @@ var LinkEditCard = function LinkEditCard(_ref) {
2390
2459
  }
2391
2460
  }, [context, selectingCellRange]);
2392
2461
  if (!isEditing) {
2462
+ var toolbarCustomConfig = customLinkTypeMap[originType];
2393
2463
  return /*#__PURE__*/React__default['default'].createElement("div", _objectSpread2(_objectSpread2({}, containerEvent), {}, {
2394
2464
  onKeyDown: function onKeyDown(e) {
2395
2465
  e.stopPropagation();
@@ -2401,16 +2471,35 @@ var LinkEditCard = function LinkEditCard(_ref) {
2401
2471
  }
2402
2472
  }), /*#__PURE__*/React__default['default'].createElement("div", {
2403
2473
  className: "link-content",
2404
- onClick: function onClick() {
2474
+ onClick: function onClick(reactEvent) {
2475
+ var _getCellHyperlink, _toolbarCustomConfig$, _settings$hooks, _settings$hooks$onHyp;
2476
+ var payload = (_getCellHyperlink = core.getCellHyperlink(context, r, c)) === null || _getCellHyperlink === void 0 ? void 0 : _getCellHyperlink.payload;
2477
+ var clickInfo = {
2478
+ linkType: originType,
2479
+ linkAddress: originAddress,
2480
+ payload: payload,
2481
+ position: {
2482
+ r: r,
2483
+ c: c,
2484
+ sheetId: context.currentSheetId
2485
+ },
2486
+ event: reactEvent
2487
+ };
2488
+ var userResult = toolbarCustomConfig === null || toolbarCustomConfig === void 0 ? void 0 : (_toolbarCustomConfig$ = toolbarCustomConfig.onClick) === null || _toolbarCustomConfig$ === void 0 ? void 0 : _toolbarCustomConfig$.call(toolbarCustomConfig, clickInfo);
2489
+ settings === null || settings === void 0 ? void 0 : (_settings$hooks = settings.hooks) === null || _settings$hooks === void 0 ? void 0 : (_settings$hooks$onHyp = _settings$hooks.onHyperlinkClick) === null || _settings$hooks$onHyp === void 0 ? void 0 : _settings$hooks$onHyp.call(_settings$hooks, clickInfo);
2490
+ if (userResult === false) {
2491
+ hideLinkCard();
2492
+ return;
2493
+ }
2405
2494
  setContext(function (draftCtx) {
2406
- return core.goToLink(draftCtx, r, c, linkType, linkAddress, refs.scrollbarX.current, refs.scrollbarY.current);
2495
+ return core.goToLink(draftCtx, r, c, originType, originAddress, refs.scrollbarX.current, refs.scrollbarY.current);
2407
2496
  });
2408
2497
  }
2409
- }, linkType === "webpage" ? insertLink.openLink : core.replaceHtml(insertLink.goTo, {
2410
- linkAddress: linkAddress
2498
+ }, originType === "webpage" ? insertLink.openLink : core.replaceHtml(insertLink.goTo, {
2499
+ linkAddress: originAddress
2411
2500
  })), context.allowEdit === true && /*#__PURE__*/React__default['default'].createElement("div", {
2412
2501
  className: "divider"
2413
- }), context.allowEdit === true && linkType === "webpage" && renderToolbarButton("copy", function () {
2502
+ }), context.allowEdit === true && originType === "webpage" && renderToolbarButton("copy", function () {
2414
2503
  navigator.clipboard.writeText(originAddress);
2415
2504
  hideLinkCard();
2416
2505
  }), context.allowEdit === true && renderToolbarButton("pencil", function () {
@@ -2489,18 +2578,23 @@ var LinkEditCard = function LinkEditCard(_ref) {
2489
2578
  className: "leankylin-link-modify-select",
2490
2579
  value: linkType,
2491
2580
  onChange: function onChange(e) {
2492
- if (e.target.value === "sheet") {
2581
+ var next = e.target.value;
2582
+ var nextCustomConfig = customLinkTypeMap[next];
2583
+ if (next === "sheet") {
2493
2584
  if (!linkText) {
2494
2585
  setLinkText(context.luckysheetfile[0].name);
2495
2586
  }
2496
2587
  setLinkAddress(context.luckysheetfile[0].name);
2588
+ } else if (nextCustomConfig) {
2589
+ setLinkAddress("");
2590
+ setCustomPayload({});
2497
2591
  } else {
2498
2592
  setLinkAddress("");
2499
2593
  }
2500
- if (e.target.value === "cellrange") setRangeModalVisible(true);
2501
- setLinkType(e.target.value);
2594
+ if (next === "cellrange") setRangeModalVisible(true);
2595
+ setLinkType(next);
2502
2596
  }
2503
- }, linkTypeList.map(function (type) {
2597
+ }, mergedLinkTypeList.map(function (type) {
2504
2598
  return /*#__PURE__*/React__default['default'].createElement("option", {
2505
2599
  key: type.value,
2506
2600
  value: type.value
@@ -2546,11 +2640,63 @@ var LinkEditCard = function LinkEditCard(_ref) {
2546
2640
  key: sheet.id,
2547
2641
  value: sheet.name
2548
2642
  }, sheet.name);
2643
+ })), tooltip)), currentCustomConfig && ( /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, currentCustomConfig.render ? currentCustomConfig.render({
2644
+ value: linkAddress,
2645
+ position: {
2646
+ r: r,
2647
+ c: c
2648
+ },
2649
+ onChange: function onChange(v) {
2650
+ return setLinkAddress(v);
2651
+ },
2652
+ setPayload: function setPayload(next) {
2653
+ setCustomPayload(function (prev) {
2654
+ return typeof next === "function" ? next(prev) : next;
2655
+ });
2656
+ },
2657
+ payload: customPayload,
2658
+ ctx: {
2659
+ context: context,
2660
+ setContext: setContext,
2661
+ settings: settings
2662
+ }
2663
+ }) : ( /*#__PURE__*/React__default['default'].createElement("input", {
2664
+ className: "leankylin-link-modify-input ".concat(canSubmit ? "" : "error-input"),
2665
+ spellCheck: "false",
2666
+ value: linkAddress,
2667
+ onChange: function onChange(e) {
2668
+ return setLinkAddress(e.target.value);
2669
+ }
2549
2670
  })), tooltip))), /*#__PURE__*/React__default['default'].createElement("div", {
2550
2671
  className: "modal-footer"
2551
2672
  }, renderBottomButton(function () {
2552
- if (!isLinkAddressValid.isValid) return;
2673
+ if (!canSubmit) return;
2553
2674
  ___default['default'].set(refs.globalCache, "linkCard.mouseEnter", false);
2675
+ if (currentCustomConfig === null || currentCustomConfig === void 0 ? void 0 : currentCustomConfig.onSave) {
2676
+ var origin = function () {
2677
+ var o = core.getCellHyperlink(context, r, c);
2678
+ return o ? {
2679
+ linkType: o.linkType,
2680
+ linkAddress: o.linkAddress,
2681
+ payload: o.payload
2682
+ } : undefined;
2683
+ }();
2684
+ var saved = currentCustomConfig.onSave({
2685
+ linkText: linkText,
2686
+ linkAddress: linkAddress,
2687
+ position: {
2688
+ r: r,
2689
+ c: c
2690
+ },
2691
+ origin: origin
2692
+ });
2693
+ if (!saved) return;
2694
+ setContext(function (draftCtx) {
2695
+ var _saved$payload;
2696
+ return core.saveHyperlink(draftCtx, r, c, linkText || saved.linkAddress, saved.linkType, saved.linkAddress, _objectSpread2(_objectSpread2({}, customPayload), (_saved$payload = saved.payload) !== null && _saved$payload !== void 0 ? _saved$payload : {}));
2697
+ });
2698
+ return;
2699
+ }
2554
2700
  setContext(function (draftCtx) {
2555
2701
  return core.saveHyperlink(draftCtx, r, c, linkText, linkType, linkAddress);
2556
2702
  });
@@ -4427,10 +4573,30 @@ var SheetOverlay = function SheetOverlay() {
4427
4573
  if (link == null) {
4428
4574
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false);
4429
4575
  } else {
4576
+ var _settings$customLinkT, _customConfig$onHover, _settings$hooks, _settings$hooks$onHyp;
4430
4577
  core.showLinkCard(ctx, rc.r, rc.c, false);
4431
4578
  debouncedShowLinkCard(globalCache, rc.r, rc.c, false, true);
4579
+ var payload = link.payload;
4580
+ var customConfigMap = ((_settings$customLinkT = settings === null || settings === void 0 ? void 0 : settings.customLinkTypes) !== null && _settings$customLinkT !== void 0 ? _settings$customLinkT : []).reduce(function (acc, it) {
4581
+ if (it.type) acc[it.type] = it;
4582
+ return acc;
4583
+ }, {});
4584
+ var customConfig = customConfigMap[link.linkType];
4585
+ var hoverInfo = {
4586
+ linkType: link.linkType,
4587
+ linkAddress: link.linkAddress,
4588
+ payload: payload,
4589
+ position: {
4590
+ r: rc.r,
4591
+ c: rc.c,
4592
+ sheetId: ctx.currentSheetId
4593
+ },
4594
+ event: e
4595
+ };
4596
+ customConfig === null || customConfig === void 0 ? void 0 : (_customConfig$onHover = customConfig.onHover) === null || _customConfig$onHover === void 0 ? void 0 : _customConfig$onHover.call(customConfig, hoverInfo);
4597
+ settings === null || settings === void 0 ? void 0 : (_settings$hooks = settings.hooks) === null || _settings$hooks === void 0 ? void 0 : (_settings$hooks$onHyp = _settings$hooks.onHyperlinkHover) === null || _settings$hooks$onHyp === void 0 ? void 0 : _settings$hooks$onHyp.call(_settings$hooks, hoverInfo);
4432
4598
  }
4433
- }, [debouncedShowLinkCard]);
4599
+ }, [debouncedShowLinkCard, settings]);
4434
4600
  var lastHoverCellRef = React.useRef(null);
4435
4601
  var onMouseMove = React.useCallback(function (nativeEvent) {
4436
4602
  var _gc$commentBox, _gc$commentBox2, _gc$searchDialog, _gc$linkCard;