@fileverse-dev/fortune-react 1.1.82 → 1.1.84

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.
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRowDragAndDrop = void 0;
7
+ var _react = require("react");
8
+ var _fortuneCore = require("@fileverse-dev/fortune-core");
9
+ var _context = _interopRequireDefault(require("../../../context"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ var useRowDragAndDrop = exports.useRowDragAndDrop = function useRowDragAndDrop(containerRef, selectedLocationRef) {
12
+ var DOUBLE_MS = 300;
13
+ var START_DRAG_THRESHOLD_PX = 6;
14
+ var clickRef = (0, _react.useRef)({
15
+ lastTime: 0,
16
+ lastRow: -1
17
+ });
18
+ var _a = (0, _react.useContext)(_context.default),
19
+ context = _a.context,
20
+ setContext = _a.setContext,
21
+ refs = _a.refs;
22
+ var dragRef = (0, _react.useRef)({
23
+ mouseDown: false,
24
+ startY: 0,
25
+ source: -1,
26
+ active: false,
27
+ lineEl: null,
28
+ ghostEl: null,
29
+ onDocMove: null,
30
+ onDocUp: null,
31
+ prevUserSelect: "",
32
+ prevWebkitUserSelect: "",
33
+ lastNativeEvent: null,
34
+ ghostHeightPx: 24
35
+ });
36
+ var removeDragLine = function removeDragLine() {
37
+ var _a = dragRef.current,
38
+ lineEl = _a.lineEl,
39
+ ghostEl = _a.ghostEl;
40
+ try {
41
+ if (lineEl === null || lineEl === void 0 ? void 0 : lineEl.parentElement) lineEl.parentElement.removeChild(lineEl);
42
+ } catch (_b) {}
43
+ try {
44
+ if (ghostEl === null || ghostEl === void 0 ? void 0 : ghostEl.parentElement) ghostEl.parentElement.removeChild(ghostEl);
45
+ } catch (_c) {}
46
+ dragRef.current.lineEl = null;
47
+ dragRef.current.ghostEl = null;
48
+ dragRef.current.active = false;
49
+ };
50
+ var getRowIndexClicked = function getRowIndexClicked(pageY, headerEl) {
51
+ var _a;
52
+ var rect = headerEl.getBoundingClientRect();
53
+ var mouseYInHeader = pageY - rect.top - window.scrollY;
54
+ var localYInHeader = mouseYInHeader + headerEl.scrollTop;
55
+ var freeze = (_a = refs.globalCache.freezen) === null || _a === void 0 ? void 0 : _a[context.currentSheetId];
56
+ var adjustedY = (0, _fortuneCore.fixPositionOnFrozenCells)(freeze, 0, localYInHeader, 0, mouseYInHeader).y;
57
+ var _b = (0, _fortuneCore.rowLocation)(adjustedY, context.visibledatarow),
58
+ rowIndex = _b[2];
59
+ return rowIndex;
60
+ };
61
+ var isRowDoubleClicked = function isRowDoubleClicked(clickedRowIndex) {
62
+ var now = performance.now();
63
+ var isDoubleClicked = now - clickRef.current.lastTime < DOUBLE_MS && clickRef.current.lastRow === clickedRowIndex;
64
+ clickRef.current.lastTime = now;
65
+ clickRef.current.lastRow = clickedRowIndex;
66
+ return isDoubleClicked;
67
+ };
68
+ var computeInsertionFromPageY = function computeInsertionFromPageY(pageY) {
69
+ var _a, _b, _c, _d, _e;
70
+ var workbookEl = containerRef.current;
71
+ if (!workbookEl) return {
72
+ insertionIndex: -1,
73
+ lineTopPx: 0,
74
+ mouseYInWorkbook: 0
75
+ };
76
+ var wbRect = workbookEl.getBoundingClientRect();
77
+ var mouseYInWorkbook = pageY - wbRect.top - window.scrollY;
78
+ var localYInWorkbook = mouseYInWorkbook + ((_b = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) !== null && _b !== void 0 ? _b : context.scrollTop);
79
+ var freeze = (_c = refs.globalCache.freezen) === null || _c === void 0 ? void 0 : _c[context.currentSheetId];
80
+ var yWorkbook = (0, _fortuneCore.fixPositionOnFrozenCells)(freeze, 0, localYInWorkbook, 0, mouseYInWorkbook).y;
81
+ var _f = (0, _fortuneCore.rowLocation)(yWorkbook, context.visibledatarow),
82
+ rowTopPx = _f[0],
83
+ rowBottomPx = _f[1],
84
+ hoveredRowIndex = _f[2];
85
+ var rowMidPx = (rowTopPx + rowBottomPx) / 2;
86
+ var insertionIndex = hoveredRowIndex + (yWorkbook > rowMidPx ? 1 : 0);
87
+ var sheetIdx = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
88
+ var sheetLocal = sheetIdx == null ? null : context.luckysheetfile[sheetIdx];
89
+ var maxRows = (_e = (_d = sheetLocal === null || sheetLocal === void 0 ? void 0 : sheetLocal.data) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : context.visibledatarow.length;
90
+ insertionIndex = Math.max(0, Math.min(maxRows, insertionIndex));
91
+ var lineTopPx = yWorkbook > rowMidPx ? rowBottomPx : rowTopPx;
92
+ return {
93
+ insertionIndex: insertionIndex,
94
+ lineTopPx: lineTopPx,
95
+ mouseYInWorkbook: mouseYInWorkbook
96
+ };
97
+ };
98
+ var createInsertionLine = function createInsertionLine(host) {
99
+ var el = document.createElement("div");
100
+ el.style.position = "absolute";
101
+ el.style.left = "0px";
102
+ el.style.right = "0px";
103
+ el.style.height = "2px";
104
+ el.style.background = "#EFC703";
105
+ el.style.zIndex = "9999";
106
+ el.style.pointerEvents = "none";
107
+ host.appendChild(el);
108
+ return el;
109
+ };
110
+ var createGhost = function createGhost(host) {
111
+ var el = document.createElement("div");
112
+ el.style.position = "fixed";
113
+ el.style.left = "45px";
114
+ el.style.width = "".concat(window.innerWidth, "px");
115
+ el.style.boxSizing = "border-box";
116
+ el.style.padding = "6px 8px";
117
+ el.style.background = "rgba(239,199,3,0.10)";
118
+ el.style.border = "1px solid #EFC703";
119
+ el.style.borderRadius = "6px";
120
+ el.style.zIndex = "10000";
121
+ el.style.pointerEvents = "none";
122
+ el.style.display = "flex";
123
+ el.style.alignItems = "center";
124
+ el.style.fontSize = "12px";
125
+ el.style.fontWeight = "500";
126
+ var ghostHeightPx = 24;
127
+ var ghostLabel = "".concat(dragRef.current.source + 1, " row");
128
+ var selectedBlock = selectedLocationRef.current.find(function (s) {
129
+ return s.r1 <= dragRef.current.source && dragRef.current.source <= s.r2;
130
+ });
131
+ if (selectedBlock) {
132
+ ghostHeightPx = Math.max(24, selectedBlock.row - selectedBlock.row_pre - 1);
133
+ var count = selectedBlock.r2 - selectedBlock.r1 + 1;
134
+ ghostLabel = count > 1 ? "".concat(count, " rows") : "".concat(selectedBlock.r1 + 1, " row");
135
+ } else {
136
+ var _a = (0, _fortuneCore.rowLocationByIndex)(dragRef.current.source, context.visibledatarow),
137
+ pre = _a[0],
138
+ end = _a[1];
139
+ var sourceRowHeight = end - pre - 1;
140
+ ghostHeightPx = Math.max(24, sourceRowHeight);
141
+ }
142
+ el.style.height = "".concat(ghostHeightPx, "px");
143
+ el.textContent = ghostLabel;
144
+ host.appendChild(el);
145
+ return {
146
+ el: el,
147
+ ghostHeightPx: ghostHeightPx
148
+ };
149
+ };
150
+ var isDragActivated = function isDragActivated(host, pixelDeltaY) {
151
+ if (dragRef.current.active) return true;
152
+ if (pixelDeltaY < START_DRAG_THRESHOLD_PX) return false;
153
+ dragRef.current.active = true;
154
+ dragRef.current.prevUserSelect = document.body.style.userSelect;
155
+ dragRef.current.prevWebkitUserSelect = document.body.style.webkitUserSelect;
156
+ document.body.style.userSelect = "none";
157
+ document.body.style.webkitUserSelect = "none";
158
+ dragRef.current.lineEl = createInsertionLine(host);
159
+ var _a = createGhost(host),
160
+ el = _a.el,
161
+ ghostHeightPx = _a.ghostHeightPx;
162
+ dragRef.current.ghostEl = el;
163
+ dragRef.current.ghostHeightPx = ghostHeightPx;
164
+ return true;
165
+ };
166
+ var handleRowDrag = function handleRowDrag(ev) {
167
+ if (!dragRef.current.mouseDown) return;
168
+ dragRef.current.lastNativeEvent = ev;
169
+ var host = containerRef.current;
170
+ if (!host) return;
171
+ var dragOffset = Math.abs(ev.pageY - dragRef.current.startY);
172
+ if (!isDragActivated(host, dragOffset)) return;
173
+ var lineTopPx = computeInsertionFromPageY(ev.pageY).lineTopPx;
174
+ var ghostPosOffset = dragRef.current.startY > ev.pageY ? 0 : 25;
175
+ if (dragRef.current.lineEl) {
176
+ dragRef.current.lineEl.style.top = "".concat(lineTopPx, "px");
177
+ }
178
+ if (dragRef.current.ghostEl) {
179
+ dragRef.current.ghostEl.style.top = "".concat(ev.pageY - ghostPosOffset, "px");
180
+ }
181
+ };
182
+ var handleRowDragEnd = function handleRowDragEnd(ev) {
183
+ if (!dragRef.current.mouseDown) return;
184
+ dragRef.current.mouseDown = false;
185
+ try {
186
+ document.body.style.userSelect = dragRef.current.prevUserSelect || "";
187
+ document.body.style.webkitUserSelect = dragRef.current.prevWebkitUserSelect || "";
188
+ } catch (_a) {}
189
+ if (dragRef.current.active) {
190
+ var finalInsertionIndex_1 = computeInsertionFromPageY(ev.pageY).insertionIndex;
191
+ var sourceIndex_1 = dragRef.current.source;
192
+ var sheetIdx_1 = (0, _fortuneCore.getSheetIndex)(context, context.currentSheetId);
193
+ if (sheetIdx_1 != null && sourceIndex_1 >= 0 && Number.isFinite(finalInsertionIndex_1) && finalInsertionIndex_1 >= 0) {
194
+ setContext(function (draft) {
195
+ var _sheet = draft.luckysheetfile[sheetIdx_1];
196
+ if (!(_sheet === null || _sheet === void 0 ? void 0 : _sheet.data)) return;
197
+ var rows = _sheet.data;
198
+ if (sourceIndex_1 < 0 || sourceIndex_1 >= rows.length) return;
199
+ var targetIndex = finalInsertionIndex_1;
200
+ if (targetIndex > sourceIndex_1) targetIndex -= 1;
201
+ var rowData = rows.splice(sourceIndex_1, 1)[0];
202
+ if (targetIndex < 0) targetIndex = 0;
203
+ if (targetIndex > rows.length) targetIndex = rows.length;
204
+ rows.splice(targetIndex, 0, rowData);
205
+ _sheet.data = rows;
206
+ (0, _fortuneCore.updateContextWithSheetData)(draft, _sheet.data);
207
+ });
208
+ }
209
+ }
210
+ removeDragLine();
211
+ dragRef.current.active = false;
212
+ dragRef.current.source = -1;
213
+ if (dragRef.current.onDocMove) document.removeEventListener("mousemove", dragRef.current.onDocMove);
214
+ if (dragRef.current.onDocUp) document.removeEventListener("mouseup", dragRef.current.onDocUp);
215
+ dragRef.current.onDocMove = null;
216
+ dragRef.current.onDocUp = null;
217
+ };
218
+ var initiateDrag = function initiateDrag(clickedRowIndex, startY) {
219
+ dragRef.current.mouseDown = true;
220
+ dragRef.current.startY = startY;
221
+ dragRef.current.source = clickedRowIndex;
222
+ dragRef.current.active = false;
223
+ dragRef.current.onDocMove = handleRowDrag;
224
+ dragRef.current.onDocUp = handleRowDragEnd;
225
+ document.addEventListener("mousemove", handleRowDrag);
226
+ document.addEventListener("mouseup", handleRowDragEnd);
227
+ };
228
+ return {
229
+ initiateDrag: initiateDrag,
230
+ getRowIndexClicked: getRowIndexClicked,
231
+ isRowDoubleClicked: isRowDoubleClicked
232
+ };
233
+ };
@@ -12,21 +12,21 @@ declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalPro
12
12
  applyOp: (ops: Op[]) => void;
13
13
  getCryptoPrice: typeof getCryptoPrice;
14
14
  getCellValue: (row: number, column: number, options?: api.CommonOptions & {
15
- type?: "rt" | "m" | "error" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
15
+ type?: "error" | "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
16
16
  }) => any;
17
17
  onboardingActiveCell: (functionName: string) => void;
18
18
  initializeComment: (row: number, column: number) => void;
19
19
  updateSheetLiveQueryList: (subsheetIndex: number, _data: import("@fileverse-dev/fortune-core").LiveQueryData) => void;
20
20
  removeFromLiveQueryList: (subSheetIndex: number, id: string) => void;
21
21
  setCellValue: (row: number, column: number, value: any, options?: api.CommonOptions & {
22
- type?: "rt" | "m" | "error" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
22
+ type?: "error" | "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle | undefined;
23
23
  }) => void;
24
24
  setCellError: (row: number, column: number, errorMessage: {
25
25
  title: string;
26
26
  message: string;
27
27
  }) => void;
28
28
  clearCell: (row: number, column: number, options?: api.CommonOptions) => void;
29
- setCellFormat: (row: number, column: number, attr: "rt" | "m" | "error" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle, value: any, options?: api.CommonOptions) => void;
29
+ setCellFormat: (row: number, column: number, attr: "error" | "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle, value: any, options?: api.CommonOptions) => void;
30
30
  autoFillCell: (copyRange: import("@fileverse-dev/fortune-core").SingleRange, applyRange: import("@fileverse-dev/fortune-core").SingleRange, direction: "left" | "right" | "down" | "up") => void;
31
31
  freeze: (type: "column" | "both" | "row", range: {
32
32
  row: number;
@@ -57,7 +57,7 @@ declare const Workbook: React.ForwardRefExoticComponent<Settings & AdditionalPro
57
57
  getHtmlByRange: (range: import("@fileverse-dev/fortune-core").Range, options?: api.CommonOptions) => string | null;
58
58
  setSelection: (range: import("@fileverse-dev/fortune-core").Range, options?: api.CommonOptions) => void;
59
59
  setCellValuesByRange: (data: any[][], range: import("@fileverse-dev/fortune-core").SingleRange, options?: api.CommonOptions) => void;
60
- setCellFormatByRange: (attr: "rt" | "m" | "error" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle, value: any, range: import("@fileverse-dev/fortune-core").SingleRange | import("@fileverse-dev/fortune-core").Range, options?: api.CommonOptions) => void;
60
+ setCellFormatByRange: (attr: "error" | "rt" | "m" | "v" | "mc" | "f" | "ct" | "qp" | "spl" | "bg" | "lo" | "baseValue" | "baseCurrency" | "baseCurrencyPrice" | "isDataBlockFormula" | "ps" | "hl" | keyof import("@fileverse-dev/fortune-core").CellStyle, value: any, range: import("@fileverse-dev/fortune-core").SingleRange | import("@fileverse-dev/fortune-core").Range, options?: api.CommonOptions) => void;
61
61
  mergeCells: (ranges: import("@fileverse-dev/fortune-core").Range, type: string, options?: api.CommonOptions) => void;
62
62
  cancelMerge: (ranges: import("@fileverse-dev/fortune-core").Range, options?: api.CommonOptions) => void;
63
63
  getAllSheets: () => SheetType[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.1.82",
3
+ "version": "1.1.84",
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.1.82",
19
+ "@fileverse-dev/fortune-core": "1.1.84",
20
20
  "@fileverse/ui": "^4.1.7-patch-21",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",