@fileverse-dev/fortune-react 1.0.15 → 1.0.17

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.
@@ -8,7 +8,7 @@ var __assign = this && this.__assign || function () {
8
8
  };
9
9
  return __assign.apply(this, arguments);
10
10
  };
11
- import { cancelNormalSelected, getCellValue, getInlineStringHTML, getStyleByCell, isInlineStringCell, moveToEnd, getFlowdata, handleFormulaInput, moveHighlightCell, escapeScriptTag, valueShowEs, createRangeHightlight, isShowHidenCR, israngeseleciton, escapeHTMLTag, isAllowEdit, getrangeseleciton } from "@fileverse-dev/fortune-core";
11
+ import { cancelNormalSelected, getCellValue, getInlineStringHTML, getStyleByCell, isInlineStringCell, moveToEnd, getFlowdata, handleFormulaInput, moveHighlightCell, escapeScriptTag, valueShowEs, createRangeHightlight, isShowHidenCR, israngeseleciton, escapeHTMLTag, isAllowEdit, getrangeseleciton, indexToColumnChar } from "@fileverse-dev/fortune-core";
12
12
  import React, { useContext, useEffect, useMemo, useRef, useCallback, useLayoutEffect, useState } from "react";
13
13
  import _ from "lodash";
14
14
  import WorkbookContext from "../../context";
@@ -17,18 +17,27 @@ import FormulaSearch from "./FormulaSearch";
17
17
  import FormulaHint from "./FormulaHint";
18
18
  import usePrevious from "../../hooks/usePrevious";
19
19
  var InputBox = function InputBox() {
20
- var _a, _b;
21
- var _c = useContext(WorkbookContext),
22
- context = _c.context,
23
- setContext = _c.setContext,
24
- refs = _c.refs;
20
+ var _a, _b, _c, _d, _e, _f;
21
+ var _g = useContext(WorkbookContext),
22
+ context = _g.context,
23
+ setContext = _g.setContext,
24
+ refs = _g.refs;
25
25
  var inputRef = useRef(null);
26
26
  var lastKeyDownEventRef = useRef(null);
27
27
  var prevCellUpdate = usePrevious(context.luckysheetCellUpdate);
28
28
  var prevSheetId = usePrevious(context.currentSheetId);
29
- var _d = useState(false),
30
- isHidenRC = _d[0],
31
- setIsHidenRC = _d[1];
29
+ var _h = useState(false),
30
+ isHidenRC = _h[0],
31
+ setIsHidenRC = _h[1];
32
+ var _j = useState(false),
33
+ isInputBoxActive = _j[0],
34
+ setIsInputBoxActive = _j[1];
35
+ var _k = useState({
36
+ left: 0,
37
+ top: 0
38
+ }),
39
+ frozenPosition = _k[0],
40
+ setFrozenPosition = _k[1];
32
41
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
33
42
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
34
43
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
@@ -99,6 +108,12 @@ var InputBox = function InputBox() {
99
108
  useEffect(function () {
100
109
  setIsHidenRC(isShowHidenCR(context));
101
110
  }, [context.luckysheet_select_save]);
111
+ useEffect(function () {
112
+ var _a;
113
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _.isEmpty(context.luckysheetCellUpdate)) {
114
+ setIsInputBoxActive(false);
115
+ }
116
+ }, [firstSelection, (_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show, context.luckysheetCellUpdate]);
102
117
  var getActiveFormula = useCallback(function () {
103
118
  return document.querySelector(".luckysheet-formula-search-item-active");
104
119
  }, []);
@@ -253,25 +268,91 @@ var InputBox = function InputBox() {
253
268
  var rowReadOnly = cfg.rowReadOnly || {};
254
269
  var colReadOnly = cfg.colReadOnly || {};
255
270
  var edit = !((colReadOnly[col_index] || rowReadOnly[row_index]) && context.allowEdit === true);
256
- return /*#__PURE__*/React.createElement("div", {
257
- className: "luckysheet-input-box",
258
- style: firstSelection && !((_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show) ? {
259
- left: firstSelection.left,
260
- top: firstSelection.top,
271
+ var getInputBoxPosition = useCallback(function () {
272
+ var _a;
273
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
274
+ return {
275
+ left: -10000,
276
+ top: -10000,
277
+ display: "block"
278
+ };
279
+ }
280
+ var canvasContainer = refs.cellArea.current;
281
+ if (!canvasContainer) {
282
+ return {
283
+ left: firstSelection.left || 0,
284
+ top: firstSelection.top || 0,
285
+ display: "block"
286
+ };
287
+ }
288
+ if (isInputBoxActive) {
289
+ return {
290
+ left: frozenPosition.left,
291
+ top: frozenPosition.top,
292
+ zIndex: _.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
293
+ display: "block"
294
+ };
295
+ }
296
+ var containerRect = canvasContainer.getBoundingClientRect();
297
+ var initialLeft = containerRect.left + (firstSelection.left || 0) - context.scrollLeft;
298
+ var initialTop = containerRect.top + (firstSelection.top || 0) - context.scrollTop;
299
+ return {
300
+ left: initialLeft,
301
+ top: initialTop,
261
302
  zIndex: _.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
262
303
  display: "block"
263
- } : {
264
- left: -10000,
265
- top: -10000,
304
+ };
305
+ }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
306
+ useEffect(function () {
307
+ var _a;
308
+ if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_.isEmpty(context.luckysheetCellUpdate)) {
309
+ var canvasContainer = refs.cellArea.current;
310
+ if (canvasContainer) {
311
+ var containerRect = canvasContainer.getBoundingClientRect();
312
+ var initialLeft = containerRect.left + (firstSelection.left || 0) - context.scrollLeft;
313
+ var initialTop = containerRect.top + (firstSelection.top || 0) - context.scrollTop;
314
+ setFrozenPosition({
315
+ left: initialLeft,
316
+ top: initialTop
317
+ });
318
+ setIsInputBoxActive(true);
319
+ }
320
+ }
321
+ }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
322
+ var getAddressIndicatorPosition = useCallback(function () {
323
+ var _a;
324
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
325
+ return {
326
+ display: "none"
327
+ };
328
+ }
329
+ return {
330
+ top: "-18px",
331
+ left: "0",
266
332
  display: "block"
267
- },
333
+ };
334
+ }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show]);
335
+ var getCellAddress = useCallback(function () {
336
+ if (!firstSelection) return "";
337
+ var rowIndex = firstSelection.row_focus || 0;
338
+ var colIndex = firstSelection.column_focus || 0;
339
+ var columnChar = indexToColumnChar(colIndex);
340
+ var rowNumber = rowIndex + 1;
341
+ return "".concat(columnChar).concat(rowNumber);
342
+ }, [firstSelection]);
343
+ return /*#__PURE__*/React.createElement("div", {
344
+ className: "luckysheet-input-box",
345
+ style: getInputBoxPosition(),
268
346
  onMouseDown: function onMouseDown(e) {
269
347
  return e.stopPropagation();
270
348
  },
271
349
  onMouseUp: function onMouseUp(e) {
272
350
  return e.stopPropagation();
273
351
  }
274
- }, /*#__PURE__*/React.createElement("div", {
352
+ }, firstSelection && !((_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show) && (/*#__PURE__*/React.createElement("div", {
353
+ className: "luckysheet-cell-address-indicator",
354
+ style: getAddressIndicatorPosition()
355
+ }, getCellAddress())), /*#__PURE__*/React.createElement("div", {
275
356
  className: "luckysheet-input-box-inner",
276
357
  style: firstSelection ? __assign({
277
358
  minWidth: firstSelection.width,
@@ -178,7 +178,7 @@
178
178
  position: absolute;
179
179
  pointer-events: none;
180
180
  z-index: 16;
181
- border: 1px dashed #0188fb;
181
+ border: 1px dashed #efc703;
182
182
  margin: -1px 0 0 -1px;
183
183
  display: none;
184
184
  }
@@ -188,7 +188,7 @@
188
188
  position: absolute;
189
189
  /* pointer-events: none; */
190
190
  z-index: 16;
191
- border: 2px solid #0188fb;
191
+ border: 2px solid #efc703;
192
192
  margin: -1px 0 0 -1px;
193
193
  display: none;
194
194
  }
@@ -197,7 +197,7 @@
197
197
  position: absolute;
198
198
  pointer-events: none;
199
199
  z-index: 15;
200
- border: 2.5px solid #0188fb;
200
+ border: 2.5px solid #efc703;
201
201
  margin: -1px 0 0 -1px;
202
202
  background: rgba(1, 136, 251, 0.15);
203
203
  display: none;
@@ -220,7 +220,7 @@
220
220
  height: 6px;
221
221
  bottom: -5px;
222
222
  cursor: crosshair;
223
- background-color: #0188fb;
223
+ background-color: #efc703;
224
224
  border: solid 1px #fff;
225
225
  z-index: 16;
226
226
  pointer-events: auto;
@@ -321,7 +321,7 @@
321
321
  }
322
322
 
323
323
  .luckysheet-input-box {
324
- position: absolute;
324
+ position: fixed;
325
325
  font: normal normal 400 13px arial, sans, sans-serif;
326
326
  z-index: 15;
327
327
  display: flex;
@@ -333,7 +333,7 @@
333
333
  text-align: left;
334
334
  max-height: 9900px;
335
335
  max-width: 9900px;
336
- border: 1px #5292f7 solid;
336
+ border: 2px #efc703 solid;
337
337
  padding: 0 2px;
338
338
  margin: 0;
339
339
  resize: none;
@@ -937,3 +937,18 @@
937
937
  overflow: hidden;
938
938
  cursor: pointer !important;
939
939
  }
940
+
941
+ .luckysheet-cell-address-indicator {
942
+ position: absolute;
943
+ top: -18px;
944
+ left: 0;
945
+ background-color: #efc703;
946
+ color: #000000;
947
+ padding: 2px 8px;
948
+ font-size: 12px;
949
+ font-weight: 500;
950
+ white-space: nowrap;
951
+ z-index: 20;
952
+ pointer-events: none;
953
+ user-select: none;
954
+ }
@@ -26,18 +26,27 @@ var __assign = void 0 && (void 0).__assign || function () {
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
28
  var InputBox = function InputBox() {
29
- var _a, _b;
30
- var _c = (0, _react.useContext)(_context.default),
31
- context = _c.context,
32
- setContext = _c.setContext,
33
- refs = _c.refs;
29
+ var _a, _b, _c, _d, _e, _f;
30
+ var _g = (0, _react.useContext)(_context.default),
31
+ context = _g.context,
32
+ setContext = _g.setContext,
33
+ refs = _g.refs;
34
34
  var inputRef = (0, _react.useRef)(null);
35
35
  var lastKeyDownEventRef = (0, _react.useRef)(null);
36
36
  var prevCellUpdate = (0, _usePrevious.default)(context.luckysheetCellUpdate);
37
37
  var prevSheetId = (0, _usePrevious.default)(context.currentSheetId);
38
- var _d = (0, _react.useState)(false),
39
- isHidenRC = _d[0],
40
- setIsHidenRC = _d[1];
38
+ var _h = (0, _react.useState)(false),
39
+ isHidenRC = _h[0],
40
+ setIsHidenRC = _h[1];
41
+ var _j = (0, _react.useState)(false),
42
+ isInputBoxActive = _j[0],
43
+ setIsInputBoxActive = _j[1];
44
+ var _k = (0, _react.useState)({
45
+ left: 0,
46
+ top: 0
47
+ }),
48
+ frozenPosition = _k[0],
49
+ setFrozenPosition = _k[1];
41
50
  var firstSelection = (_a = context.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0];
42
51
  var row_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
43
52
  var col_index = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
@@ -108,6 +117,12 @@ var InputBox = function InputBox() {
108
117
  (0, _react.useEffect)(function () {
109
118
  setIsHidenRC((0, _fortuneCore.isShowHidenCR)(context));
110
119
  }, [context.luckysheet_select_save]);
120
+ (0, _react.useEffect)(function () {
121
+ var _a;
122
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) || _lodash.default.isEmpty(context.luckysheetCellUpdate)) {
123
+ setIsInputBoxActive(false);
124
+ }
125
+ }, [firstSelection, (_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show, context.luckysheetCellUpdate]);
111
126
  var getActiveFormula = (0, _react.useCallback)(function () {
112
127
  return document.querySelector(".luckysheet-formula-search-item-active");
113
128
  }, []);
@@ -262,25 +277,91 @@ var InputBox = function InputBox() {
262
277
  var rowReadOnly = cfg.rowReadOnly || {};
263
278
  var colReadOnly = cfg.colReadOnly || {};
264
279
  var edit = !((colReadOnly[col_index] || rowReadOnly[row_index]) && context.allowEdit === true);
265
- return /*#__PURE__*/_react.default.createElement("div", {
266
- className: "luckysheet-input-box",
267
- style: firstSelection && !((_b = context.rangeDialog) === null || _b === void 0 ? void 0 : _b.show) ? {
268
- left: firstSelection.left,
269
- top: firstSelection.top,
280
+ var getInputBoxPosition = (0, _react.useCallback)(function () {
281
+ var _a;
282
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
283
+ return {
284
+ left: -10000,
285
+ top: -10000,
286
+ display: "block"
287
+ };
288
+ }
289
+ var canvasContainer = refs.cellArea.current;
290
+ if (!canvasContainer) {
291
+ return {
292
+ left: firstSelection.left || 0,
293
+ top: firstSelection.top || 0,
294
+ display: "block"
295
+ };
296
+ }
297
+ if (isInputBoxActive) {
298
+ return {
299
+ left: frozenPosition.left,
300
+ top: frozenPosition.top,
301
+ zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
302
+ display: "block"
303
+ };
304
+ }
305
+ var containerRect = canvasContainer.getBoundingClientRect();
306
+ var initialLeft = containerRect.left + (firstSelection.left || 0) - context.scrollLeft;
307
+ var initialTop = containerRect.top + (firstSelection.top || 0) - context.scrollTop;
308
+ return {
309
+ left: initialLeft,
310
+ top: initialTop,
270
311
  zIndex: _lodash.default.isEmpty(context.luckysheetCellUpdate) ? -1 : 19,
271
312
  display: "block"
272
- } : {
273
- left: -10000,
274
- top: -10000,
313
+ };
314
+ }, [firstSelection, (_c = context.rangeDialog) === null || _c === void 0 ? void 0 : _c.show, context.luckysheetCellUpdate, refs.cellArea, isInputBoxActive, frozenPosition, context.scrollLeft, context.scrollTop]);
315
+ (0, _react.useEffect)(function () {
316
+ var _a;
317
+ if (firstSelection && !((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show) && !isInputBoxActive && !_lodash.default.isEmpty(context.luckysheetCellUpdate)) {
318
+ var canvasContainer = refs.cellArea.current;
319
+ if (canvasContainer) {
320
+ var containerRect = canvasContainer.getBoundingClientRect();
321
+ var initialLeft = containerRect.left + (firstSelection.left || 0) - context.scrollLeft;
322
+ var initialTop = containerRect.top + (firstSelection.top || 0) - context.scrollTop;
323
+ setFrozenPosition({
324
+ left: initialLeft,
325
+ top: initialTop
326
+ });
327
+ setIsInputBoxActive(true);
328
+ }
329
+ }
330
+ }, [firstSelection, (_d = context.rangeDialog) === null || _d === void 0 ? void 0 : _d.show, context.luckysheetCellUpdate, isInputBoxActive, context.scrollLeft, context.scrollTop, refs.cellArea]);
331
+ var getAddressIndicatorPosition = (0, _react.useCallback)(function () {
332
+ var _a;
333
+ if (!firstSelection || ((_a = context.rangeDialog) === null || _a === void 0 ? void 0 : _a.show)) {
334
+ return {
335
+ display: "none"
336
+ };
337
+ }
338
+ return {
339
+ top: "-18px",
340
+ left: "0",
275
341
  display: "block"
276
- },
342
+ };
343
+ }, [firstSelection, (_e = context.rangeDialog) === null || _e === void 0 ? void 0 : _e.show]);
344
+ var getCellAddress = (0, _react.useCallback)(function () {
345
+ if (!firstSelection) return "";
346
+ var rowIndex = firstSelection.row_focus || 0;
347
+ var colIndex = firstSelection.column_focus || 0;
348
+ var columnChar = (0, _fortuneCore.indexToColumnChar)(colIndex);
349
+ var rowNumber = rowIndex + 1;
350
+ return "".concat(columnChar).concat(rowNumber);
351
+ }, [firstSelection]);
352
+ return /*#__PURE__*/_react.default.createElement("div", {
353
+ className: "luckysheet-input-box",
354
+ style: getInputBoxPosition(),
277
355
  onMouseDown: function onMouseDown(e) {
278
356
  return e.stopPropagation();
279
357
  },
280
358
  onMouseUp: function onMouseUp(e) {
281
359
  return e.stopPropagation();
282
360
  }
283
- }, /*#__PURE__*/_react.default.createElement("div", {
361
+ }, firstSelection && !((_f = context.rangeDialog) === null || _f === void 0 ? void 0 : _f.show) && (/*#__PURE__*/_react.default.createElement("div", {
362
+ className: "luckysheet-cell-address-indicator",
363
+ style: getAddressIndicatorPosition()
364
+ }, getCellAddress())), /*#__PURE__*/_react.default.createElement("div", {
284
365
  className: "luckysheet-input-box-inner",
285
366
  style: firstSelection ? __assign({
286
367
  minWidth: firstSelection.width,
@@ -178,7 +178,7 @@
178
178
  position: absolute;
179
179
  pointer-events: none;
180
180
  z-index: 16;
181
- border: 1px dashed #0188fb;
181
+ border: 1px dashed #efc703;
182
182
  margin: -1px 0 0 -1px;
183
183
  display: none;
184
184
  }
@@ -188,7 +188,7 @@
188
188
  position: absolute;
189
189
  /* pointer-events: none; */
190
190
  z-index: 16;
191
- border: 2px solid #0188fb;
191
+ border: 2px solid #efc703;
192
192
  margin: -1px 0 0 -1px;
193
193
  display: none;
194
194
  }
@@ -197,7 +197,7 @@
197
197
  position: absolute;
198
198
  pointer-events: none;
199
199
  z-index: 15;
200
- border: 2.5px solid #0188fb;
200
+ border: 2.5px solid #efc703;
201
201
  margin: -1px 0 0 -1px;
202
202
  background: rgba(1, 136, 251, 0.15);
203
203
  display: none;
@@ -220,7 +220,7 @@
220
220
  height: 6px;
221
221
  bottom: -5px;
222
222
  cursor: crosshair;
223
- background-color: #0188fb;
223
+ background-color: #efc703;
224
224
  border: solid 1px #fff;
225
225
  z-index: 16;
226
226
  pointer-events: auto;
@@ -321,7 +321,7 @@
321
321
  }
322
322
 
323
323
  .luckysheet-input-box {
324
- position: absolute;
324
+ position: fixed;
325
325
  font: normal normal 400 13px arial, sans, sans-serif;
326
326
  z-index: 15;
327
327
  display: flex;
@@ -333,7 +333,7 @@
333
333
  text-align: left;
334
334
  max-height: 9900px;
335
335
  max-width: 9900px;
336
- border: 1px #5292f7 solid;
336
+ border: 2px #efc703 solid;
337
337
  padding: 0 2px;
338
338
  margin: 0;
339
339
  resize: none;
@@ -937,3 +937,18 @@
937
937
  overflow: hidden;
938
938
  cursor: pointer !important;
939
939
  }
940
+
941
+ .luckysheet-cell-address-indicator {
942
+ position: absolute;
943
+ top: -18px;
944
+ left: 0;
945
+ background-color: #efc703;
946
+ color: #000000;
947
+ padding: 2px 8px;
948
+ font-size: 12px;
949
+ font-weight: 500;
950
+ white-space: nowrap;
951
+ z-index: 20;
952
+ pointer-events: none;
953
+ user-select: none;
954
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.0.14",
19
+ "@fileverse-dev/fortune-core": "1.0.17",
20
20
  "@fileverse/ui": "^4.1.7-patch-16",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",