@fileverse-dev/fortune-react 1.1.54-patch-3 → 1.1.54
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/es/components/SheetOverlay/FormulaHint/dragable-div.d.ts +9 -0
- package/es/components/SheetOverlay/FormulaHint/dragable-div.js +129 -0
- package/es/components/SheetOverlay/helper.d.ts +1 -0
- package/es/components/SheetOverlay/helper.js +25 -0
- package/lib/components/SheetOverlay/FormulaHint/dragable-div.d.ts +9 -0
- package/lib/components/SheetOverlay/FormulaHint/dragable-div.js +135 -0
- package/lib/components/SheetOverlay/helper.d.ts +1 -0
- package/lib/components/SheetOverlay/helper.js +26 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface DraggableDivProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
initialX?: number;
|
|
6
|
+
initialY?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function DraggableDiv({ children, className, initialX, initialY }: DraggableDivProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useState, useRef, useCallback } from "react";
|
|
5
|
+
import { cn } from "@fileverse/ui";
|
|
6
|
+
export function DraggableDiv(_a) {
|
|
7
|
+
var children = _a.children,
|
|
8
|
+
className = _a.className,
|
|
9
|
+
_b = _a.initialX,
|
|
10
|
+
initialX = _b === void 0 ? 100 : _b,
|
|
11
|
+
_c = _a.initialY,
|
|
12
|
+
initialY = _c === void 0 ? 100 : _c;
|
|
13
|
+
var _d = useState({
|
|
14
|
+
x: initialX,
|
|
15
|
+
y: initialY
|
|
16
|
+
}),
|
|
17
|
+
position = _d[0],
|
|
18
|
+
setPosition = _d[1];
|
|
19
|
+
var _e = useState(false),
|
|
20
|
+
isDragging = _e[0],
|
|
21
|
+
setIsDragging = _e[1];
|
|
22
|
+
var _f = useState({
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0
|
|
25
|
+
}),
|
|
26
|
+
dragStart = _f[0],
|
|
27
|
+
setDragStart = _f[1];
|
|
28
|
+
var _g = useState({
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0
|
|
31
|
+
}),
|
|
32
|
+
dragOffset = _g[0],
|
|
33
|
+
setDragOffset = _g[1];
|
|
34
|
+
var divRef = useRef(null);
|
|
35
|
+
var handleMouseDown = useCallback(function (e) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
setIsDragging(true);
|
|
38
|
+
setDragStart({
|
|
39
|
+
x: e.clientX,
|
|
40
|
+
y: e.clientY
|
|
41
|
+
});
|
|
42
|
+
setDragOffset({
|
|
43
|
+
x: e.clientX,
|
|
44
|
+
y: e.clientY
|
|
45
|
+
});
|
|
46
|
+
}, [position.x, position.y]);
|
|
47
|
+
var handleMouseMove = useCallback(function (e) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (!isDragging) return;
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
var newX = e.clientX - dragOffset.x;
|
|
52
|
+
var newY = e.clientY - dragOffset.y;
|
|
53
|
+
var divWidth = ((_a = divRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
54
|
+
var divHeight = ((_b = divRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
55
|
+
var maxX = window.innerWidth - divWidth;
|
|
56
|
+
var maxY = window.innerHeight - divHeight;
|
|
57
|
+
setPosition({
|
|
58
|
+
x: Math.max(-divWidth + 50, Math.min(newX, maxX)),
|
|
59
|
+
y: Math.max(-divHeight + 50, Math.min(newY, maxY))
|
|
60
|
+
});
|
|
61
|
+
}, [isDragging, dragOffset]);
|
|
62
|
+
var handleMouseUp = useCallback(function () {
|
|
63
|
+
setIsDragging(false);
|
|
64
|
+
}, []);
|
|
65
|
+
React.useEffect(function () {
|
|
66
|
+
if (isDragging) {
|
|
67
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
68
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
69
|
+
return function () {
|
|
70
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
71
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
75
|
+
var handleTouchStart = useCallback(function (e) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
var touch = e.touches[0];
|
|
78
|
+
setIsDragging(true);
|
|
79
|
+
setDragStart({
|
|
80
|
+
x: touch.clientX,
|
|
81
|
+
y: touch.clientY
|
|
82
|
+
});
|
|
83
|
+
setDragOffset({
|
|
84
|
+
x: touch.clientX - position.x,
|
|
85
|
+
y: touch.clientY - position.y
|
|
86
|
+
});
|
|
87
|
+
}, [position.x, position.y]);
|
|
88
|
+
var handleTouchMove = useCallback(function (e) {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
if (!isDragging) return;
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
var touch = e.touches[0];
|
|
93
|
+
var newX = touch.clientX - dragOffset.x;
|
|
94
|
+
var newY = touch.clientY - dragOffset.y;
|
|
95
|
+
var divWidth = ((_a = divRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
96
|
+
var divHeight = ((_b = divRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
97
|
+
var maxX = window.innerWidth - divWidth;
|
|
98
|
+
var maxY = window.innerHeight - divHeight;
|
|
99
|
+
setPosition({
|
|
100
|
+
x: Math.max(-divWidth + 50, Math.min(newX, maxX)),
|
|
101
|
+
y: Math.max(-divHeight + 50, Math.min(newY, maxY))
|
|
102
|
+
});
|
|
103
|
+
}, [isDragging, dragOffset]);
|
|
104
|
+
var handleTouchEnd = useCallback(function () {
|
|
105
|
+
setIsDragging(false);
|
|
106
|
+
}, []);
|
|
107
|
+
React.useEffect(function () {
|
|
108
|
+
if (isDragging) {
|
|
109
|
+
document.addEventListener("touchmove", handleTouchMove, {
|
|
110
|
+
passive: false
|
|
111
|
+
});
|
|
112
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
113
|
+
return function () {
|
|
114
|
+
document.removeEventListener("touchmove", handleTouchMove);
|
|
115
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}, [isDragging, handleTouchMove, handleTouchEnd]);
|
|
119
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
ref: divRef,
|
|
121
|
+
className: cn("absolute select-none touch-none transition-shadow duration-200", isDragging ? "cursor-grabbing shadow-2xl z-50" : "cursor-grab shadow-lg", className),
|
|
122
|
+
style: {
|
|
123
|
+
left: "".concat(position.x, "px"),
|
|
124
|
+
top: "".concat(position.y, "px")
|
|
125
|
+
},
|
|
126
|
+
onMouseDown: handleMouseDown,
|
|
127
|
+
onTouchStart: handleTouchStart
|
|
128
|
+
}, children);
|
|
129
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
|
|
2
2
|
export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
|
|
3
|
+
export declare function setCursorPosition(editableDiv: HTMLDivElement, pos: number): void;
|
|
3
4
|
export declare function isLetterNumberPattern(str: string): boolean;
|
|
4
5
|
export declare function removeLastSpan(htmlString: string): string;
|
|
5
6
|
export declare function incrementColumn(cell: string): string;
|
|
@@ -18,6 +18,31 @@ export function getCursorPosition(editableDiv) {
|
|
|
18
18
|
preRange.setEnd(range.endContainer, range.endOffset);
|
|
19
19
|
return preRange.toString().length;
|
|
20
20
|
}
|
|
21
|
+
export function setCursorPosition(editableDiv, pos) {
|
|
22
|
+
editableDiv.focus();
|
|
23
|
+
var selection = window.getSelection();
|
|
24
|
+
if (!selection) return;
|
|
25
|
+
var range = document.createRange();
|
|
26
|
+
var charIndex = 0;
|
|
27
|
+
var nodeStack = [editableDiv];
|
|
28
|
+
var node;
|
|
29
|
+
while (node = nodeStack.pop()) {
|
|
30
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
31
|
+
var textNode = node;
|
|
32
|
+
var nextCharIndex = charIndex + textNode.length;
|
|
33
|
+
if (pos <= nextCharIndex) {
|
|
34
|
+
range.setStart(textNode, pos - charIndex);
|
|
35
|
+
range.collapse(true);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
charIndex = nextCharIndex;
|
|
39
|
+
} else {
|
|
40
|
+
nodeStack.push.apply(nodeStack, Array.from(node.childNodes).reverse());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
selection.removeAllRanges();
|
|
44
|
+
selection.addRange(range);
|
|
45
|
+
}
|
|
21
46
|
export function isLetterNumberPattern(str) {
|
|
22
47
|
var regex = /^[a-zA-Z]+\d+$/;
|
|
23
48
|
return regex.test(str);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface DraggableDivProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
initialX?: number;
|
|
6
|
+
initialY?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function DraggableDiv({ children, className, initialX, initialY }: DraggableDivProps): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DraggableDiv = DraggableDiv;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _ui = require("@fileverse/ui");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
12
|
+
function DraggableDiv(_a) {
|
|
13
|
+
var children = _a.children,
|
|
14
|
+
className = _a.className,
|
|
15
|
+
_b = _a.initialX,
|
|
16
|
+
initialX = _b === void 0 ? 100 : _b,
|
|
17
|
+
_c = _a.initialY,
|
|
18
|
+
initialY = _c === void 0 ? 100 : _c;
|
|
19
|
+
var _d = (0, _react.useState)({
|
|
20
|
+
x: initialX,
|
|
21
|
+
y: initialY
|
|
22
|
+
}),
|
|
23
|
+
position = _d[0],
|
|
24
|
+
setPosition = _d[1];
|
|
25
|
+
var _e = (0, _react.useState)(false),
|
|
26
|
+
isDragging = _e[0],
|
|
27
|
+
setIsDragging = _e[1];
|
|
28
|
+
var _f = (0, _react.useState)({
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0
|
|
31
|
+
}),
|
|
32
|
+
dragStart = _f[0],
|
|
33
|
+
setDragStart = _f[1];
|
|
34
|
+
var _g = (0, _react.useState)({
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0
|
|
37
|
+
}),
|
|
38
|
+
dragOffset = _g[0],
|
|
39
|
+
setDragOffset = _g[1];
|
|
40
|
+
var divRef = (0, _react.useRef)(null);
|
|
41
|
+
var handleMouseDown = (0, _react.useCallback)(function (e) {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
setIsDragging(true);
|
|
44
|
+
setDragStart({
|
|
45
|
+
x: e.clientX,
|
|
46
|
+
y: e.clientY
|
|
47
|
+
});
|
|
48
|
+
setDragOffset({
|
|
49
|
+
x: e.clientX,
|
|
50
|
+
y: e.clientY
|
|
51
|
+
});
|
|
52
|
+
}, [position.x, position.y]);
|
|
53
|
+
var handleMouseMove = (0, _react.useCallback)(function (e) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
if (!isDragging) return;
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
var newX = e.clientX - dragOffset.x;
|
|
58
|
+
var newY = e.clientY - dragOffset.y;
|
|
59
|
+
var divWidth = ((_a = divRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
60
|
+
var divHeight = ((_b = divRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
61
|
+
var maxX = window.innerWidth - divWidth;
|
|
62
|
+
var maxY = window.innerHeight - divHeight;
|
|
63
|
+
setPosition({
|
|
64
|
+
x: Math.max(-divWidth + 50, Math.min(newX, maxX)),
|
|
65
|
+
y: Math.max(-divHeight + 50, Math.min(newY, maxY))
|
|
66
|
+
});
|
|
67
|
+
}, [isDragging, dragOffset]);
|
|
68
|
+
var handleMouseUp = (0, _react.useCallback)(function () {
|
|
69
|
+
setIsDragging(false);
|
|
70
|
+
}, []);
|
|
71
|
+
_react.default.useEffect(function () {
|
|
72
|
+
if (isDragging) {
|
|
73
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
74
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
75
|
+
return function () {
|
|
76
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
77
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
81
|
+
var handleTouchStart = (0, _react.useCallback)(function (e) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
var touch = e.touches[0];
|
|
84
|
+
setIsDragging(true);
|
|
85
|
+
setDragStart({
|
|
86
|
+
x: touch.clientX,
|
|
87
|
+
y: touch.clientY
|
|
88
|
+
});
|
|
89
|
+
setDragOffset({
|
|
90
|
+
x: touch.clientX - position.x,
|
|
91
|
+
y: touch.clientY - position.y
|
|
92
|
+
});
|
|
93
|
+
}, [position.x, position.y]);
|
|
94
|
+
var handleTouchMove = (0, _react.useCallback)(function (e) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
if (!isDragging) return;
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
var touch = e.touches[0];
|
|
99
|
+
var newX = touch.clientX - dragOffset.x;
|
|
100
|
+
var newY = touch.clientY - dragOffset.y;
|
|
101
|
+
var divWidth = ((_a = divRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
102
|
+
var divHeight = ((_b = divRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
103
|
+
var maxX = window.innerWidth - divWidth;
|
|
104
|
+
var maxY = window.innerHeight - divHeight;
|
|
105
|
+
setPosition({
|
|
106
|
+
x: Math.max(-divWidth + 50, Math.min(newX, maxX)),
|
|
107
|
+
y: Math.max(-divHeight + 50, Math.min(newY, maxY))
|
|
108
|
+
});
|
|
109
|
+
}, [isDragging, dragOffset]);
|
|
110
|
+
var handleTouchEnd = (0, _react.useCallback)(function () {
|
|
111
|
+
setIsDragging(false);
|
|
112
|
+
}, []);
|
|
113
|
+
_react.default.useEffect(function () {
|
|
114
|
+
if (isDragging) {
|
|
115
|
+
document.addEventListener("touchmove", handleTouchMove, {
|
|
116
|
+
passive: false
|
|
117
|
+
});
|
|
118
|
+
document.addEventListener("touchend", handleTouchEnd);
|
|
119
|
+
return function () {
|
|
120
|
+
document.removeEventListener("touchmove", handleTouchMove);
|
|
121
|
+
document.removeEventListener("touchend", handleTouchEnd);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}, [isDragging, handleTouchMove, handleTouchEnd]);
|
|
125
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
126
|
+
ref: divRef,
|
|
127
|
+
className: (0, _ui.cn)("absolute select-none touch-none transition-shadow duration-200", isDragging ? "cursor-grabbing shadow-2xl z-50" : "cursor-grab shadow-lg", className),
|
|
128
|
+
style: {
|
|
129
|
+
left: "".concat(position.x, "px"),
|
|
130
|
+
top: "".concat(position.y, "px")
|
|
131
|
+
},
|
|
132
|
+
onMouseDown: handleMouseDown,
|
|
133
|
+
onTouchStart: handleTouchStart
|
|
134
|
+
}, children);
|
|
135
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function moveCursorToEnd(editableDiv: HTMLDivElement): void;
|
|
2
2
|
export declare function getCursorPosition(editableDiv: HTMLDivElement): number;
|
|
3
|
+
export declare function setCursorPosition(editableDiv: HTMLDivElement, pos: number): void;
|
|
3
4
|
export declare function isLetterNumberPattern(str: string): boolean;
|
|
4
5
|
export declare function removeLastSpan(htmlString: string): string;
|
|
5
6
|
export declare function incrementColumn(cell: string): string;
|
|
@@ -11,6 +11,7 @@ exports.incrementRow = incrementRow;
|
|
|
11
11
|
exports.isLetterNumberPattern = isLetterNumberPattern;
|
|
12
12
|
exports.moveCursorToEnd = moveCursorToEnd;
|
|
13
13
|
exports.removeLastSpan = removeLastSpan;
|
|
14
|
+
exports.setCursorPosition = setCursorPosition;
|
|
14
15
|
function moveCursorToEnd(editableDiv) {
|
|
15
16
|
editableDiv.focus();
|
|
16
17
|
var range = document.createRange();
|
|
@@ -31,6 +32,31 @@ function getCursorPosition(editableDiv) {
|
|
|
31
32
|
preRange.setEnd(range.endContainer, range.endOffset);
|
|
32
33
|
return preRange.toString().length;
|
|
33
34
|
}
|
|
35
|
+
function setCursorPosition(editableDiv, pos) {
|
|
36
|
+
editableDiv.focus();
|
|
37
|
+
var selection = window.getSelection();
|
|
38
|
+
if (!selection) return;
|
|
39
|
+
var range = document.createRange();
|
|
40
|
+
var charIndex = 0;
|
|
41
|
+
var nodeStack = [editableDiv];
|
|
42
|
+
var node;
|
|
43
|
+
while (node = nodeStack.pop()) {
|
|
44
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
45
|
+
var textNode = node;
|
|
46
|
+
var nextCharIndex = charIndex + textNode.length;
|
|
47
|
+
if (pos <= nextCharIndex) {
|
|
48
|
+
range.setStart(textNode, pos - charIndex);
|
|
49
|
+
range.collapse(true);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
charIndex = nextCharIndex;
|
|
53
|
+
} else {
|
|
54
|
+
nodeStack.push.apply(nodeStack, Array.from(node.childNodes).reverse());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
selection.removeAllRanges();
|
|
58
|
+
selection.addRange(range);
|
|
59
|
+
}
|
|
34
60
|
function isLetterNumberPattern(str) {
|
|
35
61
|
var regex = /^[a-zA-Z]+\d+$/;
|
|
36
62
|
return regex.test(str);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.1.54
|
|
3
|
+
"version": "1.1.54",
|
|
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": "
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.1.54",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-21",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|