@leankylin-sheet/react 4.0.0 → 4.0.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/dist/index.esm.js CHANGED
@@ -159,6 +159,57 @@ function _nonIterableSpread() {
159
159
  function _nonIterableRest() {
160
160
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
161
161
  }
162
+ function _createForOfIteratorHelper(o, allowArrayLike) {
163
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
164
+ if (!it) {
165
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
166
+ if (it) o = it;
167
+ var i = 0;
168
+ var F = function () {};
169
+ return {
170
+ s: F,
171
+ n: function () {
172
+ if (i >= o.length) return {
173
+ done: true
174
+ };
175
+ return {
176
+ done: false,
177
+ value: o[i++]
178
+ };
179
+ },
180
+ e: function (e) {
181
+ throw e;
182
+ },
183
+ f: F
184
+ };
185
+ }
186
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
187
+ }
188
+ var normalCompletion = true,
189
+ didErr = false,
190
+ err;
191
+ return {
192
+ s: function () {
193
+ it = it.call(o);
194
+ },
195
+ n: function () {
196
+ var step = it.next();
197
+ normalCompletion = step.done;
198
+ return step;
199
+ },
200
+ e: function (e) {
201
+ didErr = true;
202
+ err = e;
203
+ },
204
+ f: function () {
205
+ try {
206
+ if (!normalCompletion && it.return != null) it.return();
207
+ } finally {
208
+ if (didErr) throw err;
209
+ }
210
+ }
211
+ };
212
+ }
162
213
 
163
214
  var defaultRefs = {
164
215
  globalCache: {
@@ -630,6 +681,8 @@ var RowHeader = function RowHeader() {
630
681
  var ContentEditable = function ContentEditable(_ref) {
631
682
  var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
632
683
  var lastHtml = useRef("");
684
+ var _useContext = useContext(WorkbookContext),
685
+ settings = _useContext.settings;
633
686
  var root = useRef(null);
634
687
  var autoFocus = props.autoFocus,
635
688
  initialContent = props.initialContent,
@@ -667,7 +720,14 @@ var ContentEditable = function ContentEditable(_ref) {
667
720
  return e.stopPropagation();
668
721
  },
669
722
  onClick: function onClick(e) {
670
- return e.stopPropagation();
723
+ var _settings$onClickCont;
724
+ e.stopPropagation();
725
+ (_settings$onClickCont = settings.onClickContentEditable) === null || _settings$onClickCont === void 0 ? void 0 : _settings$onClickCont.call(settings, e);
726
+ },
727
+ onMouseEnter: function onMouseEnter(e) {
728
+ var _settings$onClickCont2;
729
+ e.stopPropagation();
730
+ (_settings$onClickCont2 = settings.onClickContentEditable) === null || _settings$onClickCont2 === void 0 ? void 0 : _settings$onClickCont2.call(settings, e);
671
731
  }
672
732
  }, _.omit(props, "innerRef", "onChange", "html", "onBlur", "autoFocus", "allowEdit", "initialContent")), {}, {
673
733
  ref: function ref(e) {
@@ -684,39 +744,295 @@ var ContentEditable = function ContentEditable(_ref) {
684
744
  }));
685
745
  };
686
746
 
747
+ function getLastTextNode(element) {
748
+ var lastText = null;
749
+ function traverse(node) {
750
+ if (node.nodeType === Node.TEXT_NODE) {
751
+ lastText = node;
752
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
753
+ for (var i = node.childNodes.length - 1; i >= 0; i -= 1) {
754
+ traverse(node.childNodes[i]);
755
+ if (lastText) break;
756
+ }
757
+ }
758
+ }
759
+ traverse(element);
760
+ return lastText;
761
+ }
762
+ function getPlainTextCursorOffset(editableDiv) {
763
+ var selection = window.getSelection();
764
+ if (!selection || selection.rangeCount === 0) return -1;
765
+ var range = selection.getRangeAt(0);
766
+ if (!editableDiv.contains(range.commonAncestorContainer)) {
767
+ return -1;
768
+ }
769
+ var textNodes = [];
770
+ function collectTextNodes(node) {
771
+ if (node.nodeType === Node.TEXT_NODE) {
772
+ textNodes.push(node);
773
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
774
+ for (var i = 0; i < node.childNodes.length; i += 1) {
775
+ collectTextNodes(node.childNodes[i]);
776
+ }
777
+ }
778
+ }
779
+ collectTextNodes(editableDiv);
780
+ var cursorTextNode = null;
781
+ var offsetInNode = 0;
782
+ var startContainer = range.startContainer;
783
+ var startOffset = range.startOffset;
784
+ if (startContainer.nodeType === Node.TEXT_NODE) {
785
+ cursorTextNode = startContainer;
786
+ offsetInNode = startOffset;
787
+ } else if (startContainer.nodeType === Node.ELEMENT_NODE) {
788
+ var childNodes = startContainer.childNodes;
789
+ var prevTextNode = null;
790
+ for (var i = 0; i < startOffset; i += 1) {
791
+ var child = childNodes[i];
792
+ if (child.nodeType === Node.TEXT_NODE) {
793
+ prevTextNode = child;
794
+ } else if (child.nodeType === Node.ELEMENT_NODE) {
795
+ var lastText = getLastTextNode(child);
796
+ if (lastText) prevTextNode = lastText;
797
+ }
798
+ }
799
+ if (prevTextNode) {
800
+ var _prevTextNode$textCon;
801
+ cursorTextNode = prevTextNode;
802
+ offsetInNode = ((_prevTextNode$textCon = prevTextNode.textContent) === null || _prevTextNode$textCon === void 0 ? void 0 : _prevTextNode$textCon.length) || 0;
803
+ } else {
804
+ return 0;
805
+ }
806
+ }
807
+ var totalOffset = 0;
808
+ for (var _i = 0, _textNodes = textNodes; _i < _textNodes.length; _i++) {
809
+ var node = _textNodes[_i];
810
+ if (node === cursorTextNode) {
811
+ totalOffset += offsetInNode;
812
+ break;
813
+ } else {
814
+ var _node$textContent;
815
+ totalOffset += ((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.length) || 0;
816
+ }
817
+ }
818
+ return totalOffset;
819
+ }
820
+ function getrangeseleciton() {
821
+ var _anchorNode$parentNod, _anchorNode$parentNod2, _anchorNode$parentEle, _anchorNode$parentEle2;
822
+ var currSelection = window.getSelection();
823
+ if (!currSelection) return null;
824
+ var anchorNode = currSelection.anchorNode,
825
+ anchorOffset = currSelection.anchorOffset;
826
+ if (!anchorNode) return null;
827
+ if (((_anchorNode$parentNod = anchorNode.parentNode) === null || _anchorNode$parentNod === void 0 ? void 0 : (_anchorNode$parentNod2 = _anchorNode$parentNod.nodeName) === null || _anchorNode$parentNod2 === void 0 ? void 0 : _anchorNode$parentNod2.toLowerCase()) === "span" && anchorOffset !== 0) {
828
+ var txt = _.trim(anchorNode.textContent || "");
829
+ if (txt.length === 0 && anchorNode.parentNode.previousSibling) {
830
+ var ahr = anchorNode.parentNode.previousSibling;
831
+ txt = _.trim(ahr.textContent || "");
832
+ return ahr;
833
+ }
834
+ return anchorNode.parentNode;
835
+ }
836
+ var anchorElement = anchorNode;
837
+ if (anchorElement.id === "luckysheet-rich-text-editor" || anchorElement.id === "luckysheet-functionbox-cell") {
838
+ var _$last;
839
+ var _txt = _.trim((_$last = _.last(anchorElement.querySelectorAll("span"))) === null || _$last === void 0 ? void 0 : _$last.innerText);
840
+ if (_txt.length === 0 && anchorElement.querySelectorAll("span").length > 1) {
841
+ var _ahr = anchorElement.querySelectorAll("span");
842
+ _txt = _.trim(_ahr[_ahr.length - 2].innerText);
843
+ return _ahr === null || _ahr === void 0 ? void 0 : _ahr[0];
844
+ }
845
+ return _.last(anchorElement.querySelectorAll("span"));
846
+ }
847
+ if ((anchorNode === null || anchorNode === void 0 ? void 0 : (_anchorNode$parentEle = anchorNode.parentElement) === null || _anchorNode$parentEle === void 0 ? void 0 : _anchorNode$parentEle.id) === "luckysheet-rich-text-editor" || (anchorNode === null || anchorNode === void 0 ? void 0 : (_anchorNode$parentEle2 = anchorNode.parentElement) === null || _anchorNode$parentEle2 === void 0 ? void 0 : _anchorNode$parentEle2.id) === "luckysheet-functionbox-cell" || anchorOffset === 0) {
848
+ var newAnchorNode = anchorOffset === 0 ? anchorNode === null || anchorNode === void 0 ? void 0 : anchorNode.parentNode : anchorNode;
849
+ if (newAnchorNode === null || newAnchorNode === void 0 ? void 0 : newAnchorNode.previousSibling) {
850
+ return newAnchorNode === null || newAnchorNode === void 0 ? void 0 : newAnchorNode.previousSibling;
851
+ }
852
+ }
853
+ return null;
854
+ }
855
+ function moveCursorToPosition(editableDiv, targetPosition) {
856
+ if (!editableDiv || editableDiv.contentEditable !== "true") {
857
+ console.warn('目标元素必须是可编辑的div(contenteditable="true")');
858
+ return;
859
+ }
860
+ if (targetPosition < 0) {
861
+ targetPosition = 0;
862
+ }
863
+ var textNodesInfo = [];
864
+ var totalLength = 0;
865
+ function traverseNodes(node) {
866
+ if (!node) return;
867
+ if (node.nodeType === Node.TEXT_NODE) {
868
+ var textLength = node.textContent.length;
869
+ totalLength += textLength;
870
+ textNodesInfo.push({
871
+ node: node,
872
+ cumulativeLength: totalLength
873
+ });
874
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
875
+ Array.from(node.childNodes).forEach(function (child) {
876
+ return traverseNodes(child);
877
+ });
878
+ }
879
+ }
880
+ traverseNodes(editableDiv);
881
+ var targetNode = null;
882
+ var offsetInNode = 0;
883
+ if (totalLength <= targetPosition) {
884
+ if (textNodesInfo.length > 0) {
885
+ var lastNodeInfo = textNodesInfo[textNodesInfo.length - 1];
886
+ targetNode = lastNodeInfo.node;
887
+ offsetInNode = lastNodeInfo.node.textContent.length;
888
+ }
889
+ } else {
890
+ var prevCumulativeLength = 0;
891
+ var _iterator = _createForOfIteratorHelper(textNodesInfo),
892
+ _step;
893
+ try {
894
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
895
+ var info = _step.value;
896
+ if (info.cumulativeLength > targetPosition) {
897
+ targetNode = info.node;
898
+ offsetInNode = targetPosition - prevCumulativeLength;
899
+ break;
900
+ }
901
+ prevCumulativeLength = info.cumulativeLength;
902
+ }
903
+ } catch (err) {
904
+ _iterator.e(err);
905
+ } finally {
906
+ _iterator.f();
907
+ }
908
+ }
909
+ if (targetNode) {
910
+ var selection = window.getSelection();
911
+ selection.removeAllRanges();
912
+ var range = document.createRange();
913
+ range.setStart(targetNode, offsetInNode);
914
+ range.setEnd(targetNode, offsetInNode);
915
+ selection.addRange(range);
916
+ }
917
+ }
918
+
687
919
  var FormulaSearch = function FormulaSearch(props) {
688
920
  var _useContext = useContext(WorkbookContext),
689
921
  context = _useContext.context,
690
922
  refs = _useContext.refs,
691
923
  settings = _useContext.settings;
924
+ var _useState = useState(""),
925
+ _useState2 = _slicedToArray(_useState, 2),
926
+ n = _useState2[0],
927
+ setN = _useState2[1];
928
+ var wrapperRf = useRef(null);
929
+ var nRef = useRef(n);
930
+ nRef.current = n;
931
+ useEffect(function () {
932
+ if (context.functionCandidates.length) {
933
+ setN(context.functionCandidates[0].n);
934
+ }
935
+ }, [context.functionCandidates]);
936
+ var fListRef = useRef([]);
937
+ fListRef.current = context.functionCandidates;
938
+ var inputN = function inputN(fnName) {
939
+ var _refs$cellInput$curre, _editor$textContent;
940
+ var offsetIndex = getPlainTextCursorOffset(refs.cellInput.current);
941
+ var text = ((_refs$cellInput$curre = refs.cellInput.current) === null || _refs$cellInput$curre === void 0 ? void 0 : _refs$cellInput$curre.innerText) || "";
942
+ var editor = getrangeseleciton();
943
+ var replaceText = (_editor$textContent = editor.textContent) === null || _editor$textContent === void 0 ? void 0 : _editor$textContent.trim();
944
+ var replaceTextLength = (replaceText === null || replaceText === void 0 ? void 0 : replaceText.length) || 0;
945
+ var newText = (text === null || text === void 0 ? void 0 : text.slice(0, offsetIndex - replaceTextLength)) + fnName + (text === null || text === void 0 ? void 0 : text.slice(offsetIndex));
946
+ refs.cellInput.current.innerHTML = functionHTMLGenerate(newText);
947
+ moveCursorToPosition(refs.cellInput.current, offsetIndex - replaceTextLength + fnName.length);
948
+ };
949
+ var viewActive = function viewActive() {
950
+ var _wrapperRf$current;
951
+ var aItem = (_wrapperRf$current = wrapperRf.current) === null || _wrapperRf$current === void 0 ? void 0 : _wrapperRf$current.querySelector(".luckysheet-formula-search-item-active");
952
+ if (aItem) {
953
+ aItem === null || aItem === void 0 ? void 0 : aItem.scrollIntoView({
954
+ block: "nearest",
955
+ behavior: "smooth"
956
+ });
957
+ }
958
+ };
959
+ useEffect(function () {
960
+ var _refs$cellInput$curre2;
961
+ var onChange = function onChange(e) {
962
+ var _fListRef$current;
963
+ if (((_fListRef$current = fListRef.current) === null || _fListRef$current === void 0 ? void 0 : _fListRef$current.length) <= 0) {
964
+ return;
965
+ }
966
+ if (e.key === "ArrowDown") {
967
+ e.preventDefault();
968
+ setN(function (_n) {
969
+ var _fListRef$current2, _fListRef$current3;
970
+ var currentIndex = Math.max((_fListRef$current2 = fListRef.current) === null || _fListRef$current2 === void 0 ? void 0 : _fListRef$current2.findIndex(function (item) {
971
+ return item.n === _n;
972
+ }), 0);
973
+ return (_fListRef$current3 = fListRef.current[(currentIndex + 1) % fListRef.current.length]) === null || _fListRef$current3 === void 0 ? void 0 : _fListRef$current3.n;
974
+ });
975
+ setTimeout(function () {
976
+ viewActive();
977
+ }, 200);
978
+ } else if (e.key === "ArrowUp") {
979
+ e.preventDefault();
980
+ setN(function (_n) {
981
+ var _fListRef$current4, _fListRef$current5;
982
+ var currentIndex = Math.max((_fListRef$current4 = fListRef.current) === null || _fListRef$current4 === void 0 ? void 0 : _fListRef$current4.findIndex(function (item) {
983
+ return item.n === _n;
984
+ }), 0);
985
+ return (_fListRef$current5 = fListRef.current[(currentIndex - 1) % fListRef.current.length]) === null || _fListRef$current5 === void 0 ? void 0 : _fListRef$current5.n;
986
+ });
987
+ setTimeout(function () {
988
+ viewActive();
989
+ }, 200);
990
+ } else if (e.key === "Enter") {
991
+ e.preventDefault();
992
+ e.stopPropagation();
993
+ if (nRef.current) {
994
+ inputN("".concat(nRef.current, "("));
995
+ }
996
+ }
997
+ };
998
+ (_refs$cellInput$curre2 = refs.cellInput.current) === null || _refs$cellInput$curre2 === void 0 ? void 0 : _refs$cellInput$curre2.addEventListener("keydown", onChange);
999
+ return function () {
1000
+ var _refs$cellInput$curre3;
1001
+ (_refs$cellInput$curre3 = refs.cellInput.current) === null || _refs$cellInput$curre3 === void 0 ? void 0 : _refs$cellInput$curre3.removeEventListener("keydown", onChange);
1002
+ };
1003
+ }, [refs.cellInput.current]);
692
1004
  if (_.isEmpty(context.functionCandidates)) return null;
693
- function moveCursorToEnd(editor) {
694
- var leftParen = editor.querySelector(".luckysheet-formula-text-lpar");
695
- var rightParen = editor.querySelector(".luckysheet-formula-text-rpar");
696
- var range = document.createRange();
697
- var selection = window.getSelection();
698
- range.setStartAfter(leftParen);
699
- range.setEndBefore(rightParen);
700
- selection.removeAllRanges();
701
- selection.addRange(range);
702
- }
703
1005
  if (settings.renderFormulaSearch) {
704
1006
  return settings.renderFormulaSearch(context.functionCandidates, functionHTMLGenerate, refs.cellInput.current);
705
1007
  }
706
1008
  return /*#__PURE__*/React.createElement("div", _objectSpread2(_objectSpread2({}, props), {}, {
707
1009
  id: "luckysheet-formula-search-c",
708
- className: "luckysheet-formula-search-c"
1010
+ className: "luckysheet-formula-search-c",
1011
+ ref: wrapperRf,
1012
+ onWheel: function onWheel(e) {
1013
+ e.preventDefault();
1014
+ e.stopPropagation();
1015
+ },
1016
+ onWheelCapture: function onWheelCapture(e) {
1017
+ e.preventDefault();
1018
+ e.stopPropagation();
1019
+ }
709
1020
  }), context.functionCandidates.map(function (v) {
710
1021
  return /*#__PURE__*/React.createElement("div", {
711
- onClick: function onClick() {
712
- var _refs$cellInput$curre;
713
- refs.cellInput.current.innerHTML = functionHTMLGenerate("=".concat(v.n, "()"));
714
- (_refs$cellInput$curre = refs.cellInput.current) === null || _refs$cellInput$curre === void 0 ? void 0 : _refs$cellInput$curre.focus();
715
- moveCursorToEnd(refs.cellInput.current);
1022
+ onClick: function onClick(e) {
1023
+ e.preventDefault();
1024
+ e.stopPropagation();
1025
+ inputN("".concat(v.n, "("));
1026
+ },
1027
+ onMouseEnter: function onMouseEnter() {
1028
+ setN(v.n);
1029
+ },
1030
+ onMouseDown: function onMouseDown(e) {
1031
+ return e.preventDefault();
716
1032
  },
717
1033
  key: v.n,
718
1034
  "data-func": v.n,
719
- className: "luckysheet-formula-search-item"
1035
+ className: "luckysheet-formula-search-item ".concat(n === v.n && "luckysheet-formula-search-item-active")
720
1036
  }, /*#__PURE__*/React.createElement("div", {
721
1037
  className: "luckysheet-formula-search-func"
722
1038
  }, v.n), /*#__PURE__*/React.createElement("div", {
@@ -836,11 +1152,12 @@ function usePrevious(value) {
836
1152
  }
837
1153
 
838
1154
  var InputBox = function InputBox() {
839
- var _context$luckysheet_s, _context$rangeDialog;
1155
+ var _context$luckysheet_s, _context$rangeDialog, _settings$renderEdito;
840
1156
  var _useContext = useContext(WorkbookContext),
841
1157
  context = _useContext.context,
842
1158
  setContext = _useContext.setContext,
843
- refs = _useContext.refs;
1159
+ refs = _useContext.refs,
1160
+ settings = _useContext.settings;
844
1161
  var inputRef = useRef(null);
845
1162
  var lastKeyDownEventRef = useRef();
846
1163
  var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
@@ -1009,7 +1326,7 @@ var InputBox = function InputBox() {
1009
1326
  onKeyDown: onKeyDown,
1010
1327
  onPaste: onPaste,
1011
1328
  allowEdit: edit ? !isHidenRC : edit
1012
- })), document.activeElement === inputRef.current && ( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormulaSearch, {
1329
+ })), document.activeElement === inputRef.current && ( /*#__PURE__*/React.createElement(React.Fragment, null, (_settings$renderEdito = settings.renderEditorSelector) === null || _settings$renderEdito === void 0 ? void 0 : _settings$renderEdito.call(settings, inputRef.current, context.functionCandidates, context.functionHint, context.formulaCache.functionlistMap), /*#__PURE__*/React.createElement(FormulaSearch, {
1013
1330
  style: {
1014
1331
  top: ((firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.height_move) || 0) + 4
1015
1332
  }
@@ -1729,6 +2046,7 @@ var LinkEditCard = function LinkEditCard(_ref) {
1729
2046
  };
1730
2047
 
1731
2048
  var FilterOptions = function FilterOptions(_ref) {
2049
+ var _refs$globalCache$fre, _refs$globalCache$fre2;
1732
2050
  var getContainer = _ref.getContainer;
1733
2051
  var _useContext = useContext(WorkbookContext),
1734
2052
  context = _useContext.context,
@@ -1753,7 +2071,7 @@ var FilterOptions = function FilterOptions(_ref) {
1753
2071
  createFilterOptions(draftCtx, draftCtx.luckysheet_filter_save, undefined);
1754
2072
  });
1755
2073
  }, [visibledatarow, visibledatacolumn, setContext, currentSheetId, filter_select]);
1756
- var showFilterContextMenu = useCallback(function (v, i) {
2074
+ var _showFilterContextMenu = useCallback(function (v, i) {
1757
2075
  if (filterOptions == null) return;
1758
2076
  setContext(function (draftCtx) {
1759
2077
  var _draftCtx$filterConte, _draftCtx$filter$i;
@@ -1784,11 +2102,21 @@ var FilterOptions = function FilterOptions(_ref) {
1784
2102
  frozenColumns = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range = frozen.range) === null || _frozen$range === void 0 ? void 0 : _frozen$range.column_focus) || -1;
1785
2103
  frozenRows = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range2 = frozen.range) === null || _frozen$range2 === void 0 ? void 0 : _frozen$range2.row_focus) || -1;
1786
2104
  }
1787
- return filterOptions == null ? ( /*#__PURE__*/React.createElement("div", null)) : ( /*#__PURE__*/React.createElement(React.Fragment, null, filterOptions.items.map(function (v, i) {
1788
- var _refs$globalCache$fre, _refs$globalCache$fre2;
2105
+ return filterOptions == null ? ( /*#__PURE__*/React.createElement("div", null)) : ( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
2106
+ id: "luckysheet-filter-selected-sheet",
2107
+ className: "luckysheet-cell-selected luckysheet-filter-selected",
2108
+ style: _.assign({
2109
+ left: Math.max(filterOptions.left, 1),
2110
+ width: filterOptions.width,
2111
+ top: filterOptions.top,
2112
+ height: filterOptions.height,
2113
+ display: "block"
2114
+ }, fixRowStyleOverflowInFreeze(context, filterOptions.startRow, filterOptions.endRow, (_refs$globalCache$fre = refs.globalCache.freezen) === null || _refs$globalCache$fre === void 0 ? void 0 : _refs$globalCache$fre[context.currentSheetId]), fixColumnStyleOverflowInFreeze(context, filterOptions.startCol, filterOptions.endCol, (_refs$globalCache$fre2 = refs.globalCache.freezen) === null || _refs$globalCache$fre2 === void 0 ? void 0 : _refs$globalCache$fre2[context.currentSheetId]))
2115
+ }), filterOptions.items.map(function (v, i) {
2116
+ var _refs$globalCache$fre3, _refs$globalCache$fre4;
1789
2117
  var filterParam = filter[i];
1790
- var columnOverflowFreezeStyle = fixColumnStyleOverflowInFreeze(context, i + filterOptions.startCol, i + filterOptions.startCol, (_refs$globalCache$fre = refs.globalCache.freezen) === null || _refs$globalCache$fre === void 0 ? void 0 : _refs$globalCache$fre[context.currentSheetId]);
1791
- var rowOverflowFreezeStyle = fixRowStyleOverflowInFreeze(context, filterOptions.startRow, filterOptions.startRow, (_refs$globalCache$fre2 = refs.globalCache.freezen) === null || _refs$globalCache$fre2 === void 0 ? void 0 : _refs$globalCache$fre2[context.currentSheetId]);
2118
+ var columnOverflowFreezeStyle = fixColumnStyleOverflowInFreeze(context, i + filterOptions.startCol, i + filterOptions.startCol, (_refs$globalCache$fre3 = refs.globalCache.freezen) === null || _refs$globalCache$fre3 === void 0 ? void 0 : _refs$globalCache$fre3[context.currentSheetId]);
2119
+ var rowOverflowFreezeStyle = fixRowStyleOverflowInFreeze(context, filterOptions.startRow, filterOptions.startRow, (_refs$globalCache$fre4 = refs.globalCache.freezen) === null || _refs$globalCache$fre4 === void 0 ? void 0 : _refs$globalCache$fre4[context.currentSheetId]);
1792
2120
  var col = visibledatacolumn[v.col];
1793
2121
  var col_pre = v.col > 0 ? visibledatacolumn[v.col - 1] : 0;
1794
2122
  var left = v.col <= frozenColumns && columnOverflowFreezeStyle.left ? columnOverflowFreezeStyle.left + col - col_pre - 20 : v.left;
@@ -1798,20 +2126,20 @@ var FilterOptions = function FilterOptions(_ref) {
1798
2126
  top: top
1799
2127
  });
1800
2128
  if (settings.renderFilter) {
1801
- return /*#__PURE__*/React.createElement("div", {
1802
- onMouseDown: function onMouseDown(e) {
1803
- return e.stopPropagation();
1804
- },
1805
- onClick: function onClick(e) {
1806
- e.stopPropagation();
1807
- },
1808
- style: {
1809
- position: "absolute",
2129
+ return settings.renderFilter({
2130
+ style: _.assign(rowOverflowFreezeStyle, columnOverflowFreezeStyle, {
1810
2131
  left: left,
1811
2132
  top: top,
1812
- zIndex: 999
2133
+ height: undefined,
2134
+ width: undefined,
2135
+ position: "absolute",
2136
+ zIndex: 200
2137
+ }),
2138
+ filterParam: filterParam,
2139
+ showFilterContextMenu: function showFilterContextMenu() {
2140
+ return _showFilterContextMenu(v_adjusted, i);
1813
2141
  }
1814
- }, settings.renderFilter());
2142
+ });
1815
2143
  }
1816
2144
  return /*#__PURE__*/React.createElement("div", {
1817
2145
  onMouseDown: function onMouseDown(e) {
@@ -1819,7 +2147,7 @@ var FilterOptions = function FilterOptions(_ref) {
1819
2147
  },
1820
2148
  onClick: function onClick(e) {
1821
2149
  e.stopPropagation();
1822
- showFilterContextMenu(v_adjusted, i);
2150
+ _showFilterContextMenu(v_adjusted, i);
1823
2151
  },
1824
2152
  onDoubleClick: function onDoubleClick(e) {
1825
2153
  return e.stopPropagation();
@@ -5036,7 +5364,8 @@ var CustomColor = function CustomColor(_ref) {
5036
5364
  var onCustomPick = _ref.onCustomPick,
5037
5365
  onColorPick = _ref.onColorPick;
5038
5366
  var _useContext = useContext(WorkbookContext),
5039
- context = _useContext.context;
5367
+ context = _useContext.context,
5368
+ settings = _useContext.settings;
5040
5369
  var _locale = locale(context),
5041
5370
  toolbar = _locale.toolbar,
5042
5371
  sheetconfig = _locale.sheetconfig,
@@ -5045,6 +5374,12 @@ var CustomColor = function CustomColor(_ref) {
5045
5374
  _useState2 = _slicedToArray(_useState, 2),
5046
5375
  inputColor = _useState2[0],
5047
5376
  setInputColor = _useState2[1];
5377
+ if (settings.renderCustomColor) {
5378
+ return settings.renderCustomColor({
5379
+ onCustomPick: onCustomPick,
5380
+ onColorPick: onColorPick
5381
+ });
5382
+ }
5048
5383
  return /*#__PURE__*/React.createElement("div", {
5049
5384
  id: "leankylin-custom-color"
5050
5385
  }, /*#__PURE__*/React.createElement("div", {
@@ -5401,7 +5736,7 @@ var FormatSearch = function FormatSearch(_ref) {
5401
5736
  };
5402
5737
 
5403
5738
  var Toolbar = function Toolbar(_ref) {
5404
- var _context$luckysheet_s, _flowdata$row, _settings$customToolb;
5739
+ var _context$luckysheet_s, _flowdata$row, _settings$customToolb, _settings$toolbarRigh;
5405
5740
  var setMoreItems = _ref.setMoreItems,
5406
5741
  moreItemsOpen = _ref.moreItemsOpen;
5407
5742
  var _useContext = useContext(WorkbookContext),
@@ -5509,8 +5844,10 @@ var Toolbar = function Toolbar(_ref) {
5509
5844
  if (!container) return;
5510
5845
  var moreButtonWidth = 50;
5511
5846
  for (var i = itemLocations.length - 1; i >= 0; i -= 1) {
5847
+ var _container$querySelec;
5512
5848
  var loc = itemLocations[i];
5513
- if (loc + moreButtonWidth < container.clientWidth) {
5849
+ var wrapperWidth = container.clientWidth - (((_container$querySelec = container.querySelector(".leankylin-toolbar-right")) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.clientWidth) || 0);
5850
+ if (loc + moreButtonWidth < wrapperWidth) {
5514
5851
  setToolbarWrapIndex(i - itemLocations.length + settings.toolbarItems.length);
5515
5852
  if (i === itemLocations.length - 1) {
5516
5853
  setMoreItems(null);
@@ -5545,7 +5882,7 @@ var Toolbar = function Toolbar(_ref) {
5545
5882
  key: name
5546
5883
  }, /*#__PURE__*/React.createElement("div", {
5547
5884
  style: {
5548
- width: 17,
5885
+ width: 30,
5549
5886
  height: 2,
5550
5887
  backgroundColor: name === "font-color" ? refs.globalCache.recentTextColor : refs.globalCache.recentBackgroundColor,
5551
5888
  position: "absolute",
@@ -6528,7 +6865,9 @@ var Toolbar = function Toolbar(_ref) {
6528
6865
  }));
6529
6866
  }
6530
6867
  }
6531
- })) : null);
6868
+ })) : null, settings.toolbarRightRender ? ( /*#__PURE__*/React.createElement("div", {
6869
+ className: "leankylin-toolbar-right"
6870
+ }, (_settings$toolbarRigh = settings.toolbarRightRender) === null || _settings$toolbarRigh === void 0 ? void 0 : _settings$toolbarRigh.call(settings))) : null);
6532
6871
  };
6533
6872
 
6534
6873
  var LocationBox = function LocationBox() {
@@ -7564,7 +7903,10 @@ var ContextMenu = function ContextMenu() {
7564
7903
  onKeyDown: function onKeyDown(e) {
7565
7904
  return e.stopPropagation();
7566
7905
  },
7567
- type: "text",
7906
+ onMouseDown: function onMouseDown(e) {
7907
+ return e.stopPropagation();
7908
+ },
7909
+ type: "number",
7568
7910
  className: "luckysheet-mousedown-cancel",
7569
7911
  placeholder: rightclick.number,
7570
7912
  defaultValue: "1"
@@ -7617,7 +7959,10 @@ var ContextMenu = function ContextMenu() {
7617
7959
  onKeyDown: function onKeyDown(e) {
7618
7960
  return e.stopPropagation();
7619
7961
  },
7620
- type: "text",
7962
+ onMouseDown: function onMouseDown(e) {
7963
+ return e.stopPropagation();
7964
+ },
7965
+ type: "number",
7621
7966
  className: "luckysheet-mousedown-cancel",
7622
7967
  placeholder: rightclick.number,
7623
7968
  defaultValue: "1"
@@ -7813,15 +8158,15 @@ var ContextMenu = function ContextMenu() {
7813
8158
  onKeyDown: function onKeyDown(e) {
7814
8159
  return e.stopPropagation();
7815
8160
  },
8161
+ onMouseDown: function onMouseDown(e) {
8162
+ return e.stopPropagation();
8163
+ },
7816
8164
  type: "number",
7817
8165
  min: 1,
7818
8166
  max: 545,
7819
8167
  className: "luckysheet-mousedown-cancel",
7820
8168
  placeholder: rightclick.number,
7821
- defaultValue: shownRowHeight,
7822
- style: {
7823
- width: "40px"
7824
- }
8169
+ defaultValue: shownRowHeight
7825
8170
  }), "px")) : null;
7826
8171
  }
7827
8172
  if (name === "set-column-width") {
@@ -7861,6 +8206,9 @@ var ContextMenu = function ContextMenu() {
7861
8206
  onKeyDown: function onKeyDown(e) {
7862
8207
  return e.stopPropagation();
7863
8208
  },
8209
+ onMouseDown: function onMouseDown(e) {
8210
+ return e.stopPropagation();
8211
+ },
7864
8212
  type: "number",
7865
8213
  min: 1,
7866
8214
  max: 545,
@@ -8025,11 +8373,11 @@ var ContextMenu = function ContextMenu() {
8025
8373
  left: contextMenu.x,
8026
8374
  top: contextMenu.y
8027
8375
  }
8028
- }, context.contextMenu.headerMenu === true ? settings.headerContextMenu.map(function (menu, i) {
8376
+ }, renderCustom(), context.contextMenu.headerMenu === true ? settings.headerContextMenu.map(function (menu, i) {
8029
8377
  return getMenuElement(menu, i);
8030
8378
  }) : settings.cellContextMenu().map(function (menu, i) {
8031
8379
  return getMenuElement(menu, i);
8032
- }), renderCustom());
8380
+ }));
8033
8381
  };
8034
8382
 
8035
8383
  var SVGDefines = function SVGDefines() {
@@ -9425,67 +9773,6 @@ var SVGDefines = function SVGDefines() {
9425
9773
  }))));
9426
9774
  };
9427
9775
 
9428
- var ChangeColor = function ChangeColor(_ref) {
9429
- var triggerParentUpdate = _ref.triggerParentUpdate;
9430
- var _useContext = useContext(WorkbookContext),
9431
- context = _useContext.context,
9432
- setContext = _useContext.setContext;
9433
- var _locale = locale(context),
9434
- toolbar = _locale.toolbar,
9435
- sheetconfig = _locale.sheetconfig,
9436
- button = _locale.button;
9437
- var _useState = useState("#000000"),
9438
- _useState2 = _slicedToArray(_useState, 2),
9439
- inputColor = _useState2[0],
9440
- setInputColor = _useState2[1];
9441
- var _useState3 = useState(context.luckysheetfile[getSheetIndex(context, context.currentSheetId)].color),
9442
- _useState4 = _slicedToArray(_useState3, 2),
9443
- selectColor = _useState4[0],
9444
- setSelectColor = _useState4[1];
9445
- var certainBtn = useCallback(function () {
9446
- setSelectColor(inputColor);
9447
- }, [inputColor]);
9448
- useEffect(function () {
9449
- setContext(function (ctx) {
9450
- if (ctx.allowEdit === false) return;
9451
- var index = getSheetIndex(ctx, ctx.currentSheetId);
9452
- ctx.luckysheetfile[index].color = selectColor;
9453
- });
9454
- }, [selectColor, setContext]);
9455
- return /*#__PURE__*/React.createElement("div", {
9456
- id: "leankylin-change-color"
9457
- }, /*#__PURE__*/React.createElement("div", {
9458
- className: "color-reset",
9459
- onClick: function onClick() {
9460
- return setSelectColor(undefined);
9461
- }
9462
- }, sheetconfig.resetColor), /*#__PURE__*/React.createElement("div", {
9463
- className: "custom-color"
9464
- }, /*#__PURE__*/React.createElement("div", null, toolbar.customColor, ":"), /*#__PURE__*/React.createElement("input", {
9465
- type: "color",
9466
- value: inputColor,
9467
- onChange: function onChange(e) {
9468
- return setInputColor(e.target.value);
9469
- },
9470
- onFocus: function onFocus() {
9471
- triggerParentUpdate(true);
9472
- },
9473
- onBlur: function onBlur() {
9474
- triggerParentUpdate(false);
9475
- }
9476
- }), /*#__PURE__*/React.createElement("div", {
9477
- className: "button-basic button-primary",
9478
- onClick: function onClick() {
9479
- certainBtn();
9480
- }
9481
- }, button.confirm)), /*#__PURE__*/React.createElement(ColorPicker, {
9482
- onPick: function onPick(color) {
9483
- setInputColor(color);
9484
- setSelectColor(color);
9485
- }
9486
- }));
9487
- };
9488
-
9489
9776
  var SheetTabContextMenu = function SheetTabContextMenu() {
9490
9777
  var _settings$sheetTabCon;
9491
9778
  var _useContext = useContext(WorkbookContext),
@@ -9583,6 +9870,13 @@ var SheetTabContextMenu = function SheetTabContextMenu() {
9583
9870
  });
9584
9871
  });
9585
9872
  }, [context.allowEdit, setContext, sheet === null || sheet === void 0 ? void 0 : sheet.id]);
9873
+ var changeColor = function changeColor(selectColor) {
9874
+ setContext(function (ctx) {
9875
+ if (ctx.allowEdit === false) return;
9876
+ var index = getSheetIndex(ctx, ctx.currentSheetId);
9877
+ ctx.luckysheetfile[index].color = selectColor;
9878
+ });
9879
+ };
9586
9880
  if (!sheet || x == null || y == null) return null;
9587
9881
  return /*#__PURE__*/React.createElement("div", {
9588
9882
  className: "leankylin-context-menu luckysheet-cols-menu",
@@ -9679,9 +9973,15 @@ var SheetTabContextMenu = function SheetTabContextMenu() {
9679
9973
  }, /*#__PURE__*/React.createElement(SVGIcon, {
9680
9974
  name: "rightArrow",
9681
9975
  width: 18
9682
- })), isShowChangeColor && context.allowEdit && ( /*#__PURE__*/React.createElement(ChangeColor, {
9683
- triggerParentUpdate: updateShowInputColor
9684
- })));
9976
+ })), isShowChangeColor && context.allowEdit && ( /*#__PURE__*/React.createElement("div", {
9977
+ className: "leankylin-sheet-color-change"
9978
+ }, /*#__PURE__*/React.createElement(CustomColor, {
9979
+ onCustomPick: function onCustomPick(color) {
9980
+ changeColor(color);
9981
+ setIsShowChangeColor(false);
9982
+ },
9983
+ onColorPick: changeColor
9984
+ }))));
9685
9985
  }
9686
9986
  if (name === "focus") {
9687
9987
  return /*#__PURE__*/React.createElement(Menu, {
@@ -9716,6 +10016,9 @@ var MoreItemsContaier = function MoreItemsContaier(_ref) {
9716
10016
 
9717
10017
  function generateAPIs(context, setContext, handleUndo, handleRedo, settings, cellInput, scrollbarX, scrollbarY, refs) {
9718
10018
  return {
10019
+ replaceVariables: function replaceVariables(_map) {
10020
+ context.formulaCache.parser.replaceVariables(_map);
10021
+ },
9719
10022
  setVariable: function setVariable(name, value) {
9720
10023
  context.formulaCache.parser.setVariable(name, value);
9721
10024
  },
@@ -9909,6 +10212,12 @@ function generateAPIs(context, setContext, handleUndo, handleRedo, settings, cel
9909
10212
  return api.setCellValuesByRange(draftCtx, data, range, cellInput, options);
9910
10213
  });
9911
10214
  },
10215
+ setCellValues: function setCellValues(data) {
10216
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10217
+ return setContext(function (draftCtx) {
10218
+ return api.setCellValues(draftCtx, data, cellInput, options);
10219
+ });
10220
+ },
9912
10221
  setCellFormatByRange: function setCellFormatByRange(attr, value, range) {
9913
10222
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9914
10223
  return setContext(function (draftCtx) {
@@ -10265,6 +10574,9 @@ var FilterMenu = function FilterMenu() {
10265
10574
  backgroundColor: v.color
10266
10575
  }
10267
10576
  }), /*#__PURE__*/React.createElement("input", {
10577
+ onMouseDown: function onMouseDown(e) {
10578
+ return e.stopPropagation();
10579
+ },
10268
10580
  className: "luckysheet-mousedown-cancel",
10269
10581
  type: "checkbox",
10270
10582
  checked: v.checked,
@@ -10431,11 +10743,7 @@ var FilterMenu = function FilterMenu() {
10431
10743
  if (name === "filter-by-value") {
10432
10744
  return /*#__PURE__*/React.createElement("div", {
10433
10745
  key: name
10434
- }, /*#__PURE__*/React.createElement(Menu, {
10435
- onClick: function onClick() {}
10436
10746
  }, /*#__PURE__*/React.createElement("div", {
10437
- className: "filter-caret right"
10438
- }), filter.filterByValues), /*#__PURE__*/React.createElement("div", {
10439
10747
  className: "luckysheet-filter-byvalue"
10440
10748
  }, /*#__PURE__*/React.createElement("div", {
10441
10749
  className: "leankylin-menuitem-row byvalue-btn-row"
@@ -10562,6 +10870,9 @@ var FilterMenu = function FilterMenu() {
10562
10870
  onMouseLeave: function onMouseLeave() {
10563
10871
  mouseHoverSubMenu.current = false;
10564
10872
  setShowSubMenu(false);
10873
+ },
10874
+ onMouseDown: function onMouseDown(e) {
10875
+ return e.stopPropagation();
10565
10876
  }
10566
10877
  }, filterColors.bgColors.length < 2 && filterColors.fcColors.length < 2 ? ( /*#__PURE__*/React.createElement("div", {
10567
10878
  className: "one-color-tip"