@fileverse-dev/fortune-react 1.2.49 → 1.2.50-patch-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.
@@ -12,6 +12,7 @@ export var useSmoothScroll = function useSmoothScroll(scrollContainerRef) {
12
12
  return window.devicePixelRatio || 1;
13
13
  };
14
14
  }
15
+ console.log("handleScroll called 6.2");
15
16
  var queuedXPixels = 0;
16
17
  var queuedYPixels = 0;
17
18
  var animationFrameId = 0;
@@ -69,38 +70,104 @@ export var useSmoothScroll = function useSmoothScroll(scrollContainerRef) {
69
70
  var gestureStartClientY = 0;
70
71
  var lastPointerClientX = 0;
71
72
  var lastPointerClientY = 0;
73
+ var lastMoveTime = 0;
74
+ var velocityX = 0;
75
+ var velocityY = 0;
76
+ var momentumAnimationId = 0;
77
+ var scrollDirection = "none";
72
78
  var PAN_DISTANCE_THRESHOLD_PX = 8;
79
+ var FRICTION = 0.95;
80
+ var MIN_VELOCITY = 0.5;
81
+ var VELOCITY_MULTIPLIER = 2.6;
82
+ var DIRECTION_LOCK_THRESHOLD = 1.5;
83
+ function stopMomentum() {
84
+ if (momentumAnimationId) {
85
+ cancelAnimationFrame(momentumAnimationId);
86
+ momentumAnimationId = 0;
87
+ }
88
+ velocityX = 0;
89
+ velocityY = 0;
90
+ }
91
+ function applyMomentum() {
92
+ if (Math.abs(velocityX) < MIN_VELOCITY && Math.abs(velocityY) < MIN_VELOCITY) {
93
+ stopMomentum();
94
+ return;
95
+ }
96
+ var scale = getPixelScale();
97
+ var momentumX = -velocityX * scale;
98
+ var momentumY = -velocityY * scale;
99
+ if (scrollDirection === "vertical") {
100
+ momentumX = 0;
101
+ } else if (scrollDirection === "horizontal") {
102
+ momentumY = 0;
103
+ }
104
+ scrollHandler(momentumX, momentumY);
105
+ velocityX *= FRICTION;
106
+ velocityY *= FRICTION;
107
+ momentumAnimationId = requestAnimationFrame(applyMomentum);
108
+ }
73
109
  function onPointerDown(pointerEvent) {
74
110
  if (pointerEvent.pointerType !== "touch" && pointerEvent.pointerType !== "pen") return;
111
+ stopMomentum();
75
112
  isScrolling = false;
113
+ scrollDirection = "none";
76
114
  gestureStartClientX = pointerEvent.clientX;
77
115
  lastPointerClientX = pointerEvent.clientX;
78
116
  gestureStartClientY = pointerEvent.clientY;
79
117
  lastPointerClientY = pointerEvent.clientY;
118
+ lastMoveTime = performance.now();
119
+ velocityX = 0;
120
+ velocityY = 0;
80
121
  containerEl.setPointerCapture(pointerEvent.pointerId);
81
122
  }
82
123
  function onPointerMove(pointerEvent) {
83
124
  if (pointerEvent.pointerType !== "touch" && pointerEvent.pointerType !== "pen") return;
125
+ var currentTime = performance.now();
126
+ var deltaTime = Math.max(1, currentTime - lastMoveTime);
84
127
  var deltaXSinceLastMove = pointerEvent.clientX - lastPointerClientX;
85
128
  var deltaYSinceLastMove = pointerEvent.clientY - lastPointerClientY;
129
+ velocityX = deltaXSinceLastMove / deltaTime * 16;
130
+ velocityY = deltaYSinceLastMove / deltaTime * 16;
86
131
  lastPointerClientX = pointerEvent.clientX;
87
132
  lastPointerClientY = pointerEvent.clientY;
133
+ lastMoveTime = currentTime;
88
134
  if (!isScrolling) {
89
135
  var totalXFromGestureStart = lastPointerClientX - gestureStartClientX;
90
136
  var totalYFromGestureStart = lastPointerClientY - gestureStartClientY;
91
137
  if (totalXFromGestureStart * totalXFromGestureStart + totalYFromGestureStart * totalYFromGestureStart < PAN_DISTANCE_THRESHOLD_PX * PAN_DISTANCE_THRESHOLD_PX) {
92
138
  return;
93
139
  }
140
+ var absX = Math.abs(totalXFromGestureStart);
141
+ var absY = Math.abs(totalYFromGestureStart);
142
+ if (absX > absY * DIRECTION_LOCK_THRESHOLD) {
143
+ scrollDirection = "horizontal";
144
+ } else if (absY > absX * DIRECTION_LOCK_THRESHOLD) {
145
+ scrollDirection = "vertical";
146
+ } else {
147
+ scrollDirection = "none";
148
+ }
94
149
  isScrolling = true;
95
150
  }
96
151
  pointerEvent.preventDefault();
97
152
  var scale = getPixelScale();
98
- scrollHandler(-deltaXSinceLastMove * scale, -deltaYSinceLastMove * scale);
153
+ var scrollX = -deltaXSinceLastMove * scale * VELOCITY_MULTIPLIER;
154
+ var scrollY = -deltaYSinceLastMove * scale * VELOCITY_MULTIPLIER;
155
+ if (scrollDirection === "vertical") {
156
+ scrollX = 0;
157
+ } else if (scrollDirection === "horizontal") {
158
+ scrollY = 0;
159
+ }
160
+ scrollHandler(scrollX, scrollY);
99
161
  }
100
162
  function onPointerUp(e) {
101
163
  try {
102
164
  containerEl.releasePointerCapture(e.pointerId);
103
165
  } catch (_a) {}
166
+ if (isScrolling) {
167
+ if (Math.abs(velocityX) > MIN_VELOCITY || Math.abs(velocityY) > MIN_VELOCITY) {
168
+ momentumAnimationId = requestAnimationFrame(applyMomentum);
169
+ }
170
+ }
104
171
  isScrolling = false;
105
172
  }
106
173
  containerEl.addEventListener("pointerdown", onPointerDown, {
@@ -112,6 +179,7 @@ export var useSmoothScroll = function useSmoothScroll(scrollContainerRef) {
112
179
  containerEl.addEventListener("pointerup", onPointerUp);
113
180
  containerEl.addEventListener("pointercancel", onPointerUp);
114
181
  return function () {
182
+ stopMomentum();
115
183
  containerEl.removeEventListener("pointerdown", onPointerDown);
116
184
  containerEl.removeEventListener("pointermove", onPointerMove);
117
185
  containerEl.removeEventListener("pointerup", onPointerUp);
@@ -238,7 +238,6 @@ export var useColumnDragAndDrop = function useColumnDragAndDrop(containerRef, se
238
238
  });
239
239
  selectedSourceColRef.current = selectedSourceCol;
240
240
  selectedTargetColRef.current = selectedTargetCol;
241
- console.log("selectedSourceCol", selectedTargetCol);
242
241
  selectedSourceCol.forEach(function () {
243
242
  var adjustedSourceIndex = sourceIndex_1;
244
243
  if (targetIndex < sourceIndex_1) {
@@ -4,6 +4,7 @@ import DataVerification from "../DataVerification";
4
4
  var DataVerificationPortal = function DataVerificationPortal(_a) {
5
5
  var visible = _a.visible;
6
6
  var container = document.getElementById("placeholder-data-verification");
7
+ console.log(container, !visible, !container);
7
8
  if (!visible || !container) return null;
8
9
  return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement(DataVerification, null), container);
9
10
  };
@@ -995,15 +995,13 @@ var Toolbar = function Toolbar(_a) {
995
995
  });
996
996
  }
997
997
  if (name === "dataVerification") {
998
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataVerificationPortal, {
999
- visible: showDataValidation
1000
- }), /*#__PURE__*/React.createElement(Button, {
998
+ return /*#__PURE__*/React.createElement(Button, {
1001
999
  id: "dataVerification",
1002
1000
  iconId: name,
1003
1001
  tooltip: tooltip,
1004
1002
  key: name,
1005
1003
  onClick: dataVerificationClick
1006
- }));
1004
+ });
1007
1005
  }
1008
1006
  if (name === "locationCondition") {
1009
1007
  var items_3 = [{
@@ -1136,34 +1134,7 @@ var Toolbar = function Toolbar(_a) {
1136
1134
  if (context.allowEdit === false) return;
1137
1135
  showImgChooser();
1138
1136
  }
1139
- }, /*#__PURE__*/React.createElement("input", {
1140
- id: "fortune-img-upload",
1141
- type: "file",
1142
- accept: "image/*",
1143
- style: {
1144
- display: "none"
1145
- },
1146
- onChange: function onChange(e) {
1147
- var _a;
1148
- var file = (_a = e.currentTarget.files) === null || _a === void 0 ? void 0 : _a[0];
1149
- if (!file) return;
1150
- var render = new FileReader();
1151
- render.readAsDataURL(file);
1152
- render.onload = function (event) {
1153
- var _a;
1154
- if (event.target == null) return;
1155
- var src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
1156
- var image = new Image();
1157
- image.onload = function () {
1158
- setContext(function (draftCtx) {
1159
- insertImage(draftCtx, image);
1160
- });
1161
- };
1162
- image.src = src;
1163
- };
1164
- e.currentTarget.value = "";
1165
- }
1166
- }));
1137
+ });
1167
1138
  }
1168
1139
  if (name === "comment") {
1169
1140
  var last = (_d = context.luckysheet_select_save) === null || _d === void 0 ? void 0 : _d[context.luckysheet_select_save.length - 1];
@@ -1692,7 +1663,36 @@ var Toolbar = function Toolbar(_a) {
1692
1663
  ref: containerRef,
1693
1664
  className: "fortune-toolbar",
1694
1665
  "aria-label": toolbar.toolbar
1695
- }, /*#__PURE__*/React.createElement("div", {
1666
+ }, /*#__PURE__*/React.createElement(DataVerificationPortal, {
1667
+ visible: showDataValidation
1668
+ }), /*#__PURE__*/React.createElement("input", {
1669
+ id: "fortune-img-upload",
1670
+ type: "file",
1671
+ accept: "image/*",
1672
+ style: {
1673
+ display: "none"
1674
+ },
1675
+ onChange: function onChange(e) {
1676
+ var _a;
1677
+ var file = (_a = e.currentTarget.files) === null || _a === void 0 ? void 0 : _a[0];
1678
+ if (!file) return;
1679
+ var render = new FileReader();
1680
+ render.readAsDataURL(file);
1681
+ render.onload = function (event) {
1682
+ var _a;
1683
+ if (event.target == null) return;
1684
+ var src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
1685
+ var image = new Image();
1686
+ image.onload = function () {
1687
+ setContext(function (draftCtx) {
1688
+ insertImage(draftCtx, image);
1689
+ });
1690
+ };
1691
+ image.src = src;
1692
+ };
1693
+ e.currentTarget.value = "";
1694
+ }
1695
+ }), /*#__PURE__*/React.createElement("div", {
1696
1696
  className: "fortune-toolbar-left"
1697
1697
  }, settings.customToolbarItems.filter(function (n) {
1698
1698
  return n.key === "import-export";
@@ -19,6 +19,7 @@ var useSmoothScroll = exports.useSmoothScroll = function useSmoothScroll(scrollC
19
19
  return window.devicePixelRatio || 1;
20
20
  };
21
21
  }
22
+ console.log("handleScroll called 6.2");
22
23
  var queuedXPixels = 0;
23
24
  var queuedYPixels = 0;
24
25
  var animationFrameId = 0;
@@ -76,38 +77,104 @@ var useSmoothScroll = exports.useSmoothScroll = function useSmoothScroll(scrollC
76
77
  var gestureStartClientY = 0;
77
78
  var lastPointerClientX = 0;
78
79
  var lastPointerClientY = 0;
80
+ var lastMoveTime = 0;
81
+ var velocityX = 0;
82
+ var velocityY = 0;
83
+ var momentumAnimationId = 0;
84
+ var scrollDirection = "none";
79
85
  var PAN_DISTANCE_THRESHOLD_PX = 8;
86
+ var FRICTION = 0.95;
87
+ var MIN_VELOCITY = 0.5;
88
+ var VELOCITY_MULTIPLIER = 2.6;
89
+ var DIRECTION_LOCK_THRESHOLD = 1.5;
90
+ function stopMomentum() {
91
+ if (momentumAnimationId) {
92
+ cancelAnimationFrame(momentumAnimationId);
93
+ momentumAnimationId = 0;
94
+ }
95
+ velocityX = 0;
96
+ velocityY = 0;
97
+ }
98
+ function applyMomentum() {
99
+ if (Math.abs(velocityX) < MIN_VELOCITY && Math.abs(velocityY) < MIN_VELOCITY) {
100
+ stopMomentum();
101
+ return;
102
+ }
103
+ var scale = getPixelScale();
104
+ var momentumX = -velocityX * scale;
105
+ var momentumY = -velocityY * scale;
106
+ if (scrollDirection === "vertical") {
107
+ momentumX = 0;
108
+ } else if (scrollDirection === "horizontal") {
109
+ momentumY = 0;
110
+ }
111
+ scrollHandler(momentumX, momentumY);
112
+ velocityX *= FRICTION;
113
+ velocityY *= FRICTION;
114
+ momentumAnimationId = requestAnimationFrame(applyMomentum);
115
+ }
80
116
  function onPointerDown(pointerEvent) {
81
117
  if (pointerEvent.pointerType !== "touch" && pointerEvent.pointerType !== "pen") return;
118
+ stopMomentum();
82
119
  isScrolling = false;
120
+ scrollDirection = "none";
83
121
  gestureStartClientX = pointerEvent.clientX;
84
122
  lastPointerClientX = pointerEvent.clientX;
85
123
  gestureStartClientY = pointerEvent.clientY;
86
124
  lastPointerClientY = pointerEvent.clientY;
125
+ lastMoveTime = performance.now();
126
+ velocityX = 0;
127
+ velocityY = 0;
87
128
  containerEl.setPointerCapture(pointerEvent.pointerId);
88
129
  }
89
130
  function onPointerMove(pointerEvent) {
90
131
  if (pointerEvent.pointerType !== "touch" && pointerEvent.pointerType !== "pen") return;
132
+ var currentTime = performance.now();
133
+ var deltaTime = Math.max(1, currentTime - lastMoveTime);
91
134
  var deltaXSinceLastMove = pointerEvent.clientX - lastPointerClientX;
92
135
  var deltaYSinceLastMove = pointerEvent.clientY - lastPointerClientY;
136
+ velocityX = deltaXSinceLastMove / deltaTime * 16;
137
+ velocityY = deltaYSinceLastMove / deltaTime * 16;
93
138
  lastPointerClientX = pointerEvent.clientX;
94
139
  lastPointerClientY = pointerEvent.clientY;
140
+ lastMoveTime = currentTime;
95
141
  if (!isScrolling) {
96
142
  var totalXFromGestureStart = lastPointerClientX - gestureStartClientX;
97
143
  var totalYFromGestureStart = lastPointerClientY - gestureStartClientY;
98
144
  if (totalXFromGestureStart * totalXFromGestureStart + totalYFromGestureStart * totalYFromGestureStart < PAN_DISTANCE_THRESHOLD_PX * PAN_DISTANCE_THRESHOLD_PX) {
99
145
  return;
100
146
  }
147
+ var absX = Math.abs(totalXFromGestureStart);
148
+ var absY = Math.abs(totalYFromGestureStart);
149
+ if (absX > absY * DIRECTION_LOCK_THRESHOLD) {
150
+ scrollDirection = "horizontal";
151
+ } else if (absY > absX * DIRECTION_LOCK_THRESHOLD) {
152
+ scrollDirection = "vertical";
153
+ } else {
154
+ scrollDirection = "none";
155
+ }
101
156
  isScrolling = true;
102
157
  }
103
158
  pointerEvent.preventDefault();
104
159
  var scale = getPixelScale();
105
- scrollHandler(-deltaXSinceLastMove * scale, -deltaYSinceLastMove * scale);
160
+ var scrollX = -deltaXSinceLastMove * scale * VELOCITY_MULTIPLIER;
161
+ var scrollY = -deltaYSinceLastMove * scale * VELOCITY_MULTIPLIER;
162
+ if (scrollDirection === "vertical") {
163
+ scrollX = 0;
164
+ } else if (scrollDirection === "horizontal") {
165
+ scrollY = 0;
166
+ }
167
+ scrollHandler(scrollX, scrollY);
106
168
  }
107
169
  function onPointerUp(e) {
108
170
  try {
109
171
  containerEl.releasePointerCapture(e.pointerId);
110
172
  } catch (_a) {}
173
+ if (isScrolling) {
174
+ if (Math.abs(velocityX) > MIN_VELOCITY || Math.abs(velocityY) > MIN_VELOCITY) {
175
+ momentumAnimationId = requestAnimationFrame(applyMomentum);
176
+ }
177
+ }
111
178
  isScrolling = false;
112
179
  }
113
180
  containerEl.addEventListener("pointerdown", onPointerDown, {
@@ -119,6 +186,7 @@ var useSmoothScroll = exports.useSmoothScroll = function useSmoothScroll(scrollC
119
186
  containerEl.addEventListener("pointerup", onPointerUp);
120
187
  containerEl.addEventListener("pointercancel", onPointerUp);
121
188
  return function () {
189
+ stopMomentum();
122
190
  containerEl.removeEventListener("pointerdown", onPointerDown);
123
191
  containerEl.removeEventListener("pointermove", onPointerMove);
124
192
  containerEl.removeEventListener("pointerup", onPointerUp);
@@ -246,7 +246,6 @@ var useColumnDragAndDrop = exports.useColumnDragAndDrop = function useColumnDrag
246
246
  });
247
247
  selectedSourceColRef.current = selectedSourceCol;
248
248
  selectedTargetColRef.current = selectedTargetCol;
249
- console.log("selectedSourceCol", selectedTargetCol);
250
249
  selectedSourceCol.forEach(function () {
251
250
  var adjustedSourceIndex = sourceIndex_1;
252
251
  if (targetIndex < sourceIndex_1) {
@@ -11,6 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
11
11
  var DataVerificationPortal = function DataVerificationPortal(_a) {
12
12
  var visible = _a.visible;
13
13
  var container = document.getElementById("placeholder-data-verification");
14
+ console.log(container, !visible, !container);
14
15
  if (!visible || !container) return null;
15
16
  return /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement(_DataVerification.default, null), container);
16
17
  };
@@ -1004,15 +1004,13 @@ var Toolbar = function Toolbar(_a) {
1004
1004
  });
1005
1005
  }
1006
1006
  if (name === "dataVerification") {
1007
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_dataVerificationPortal.default, {
1008
- visible: showDataValidation
1009
- }), /*#__PURE__*/_react.default.createElement(_Button.default, {
1007
+ return /*#__PURE__*/_react.default.createElement(_Button.default, {
1010
1008
  id: "dataVerification",
1011
1009
  iconId: name,
1012
1010
  tooltip: tooltip,
1013
1011
  key: name,
1014
1012
  onClick: dataVerificationClick
1015
- }));
1013
+ });
1016
1014
  }
1017
1015
  if (name === "locationCondition") {
1018
1016
  var items_3 = [{
@@ -1145,34 +1143,7 @@ var Toolbar = function Toolbar(_a) {
1145
1143
  if (context.allowEdit === false) return;
1146
1144
  (0, _fortuneCore.showImgChooser)();
1147
1145
  }
1148
- }, /*#__PURE__*/_react.default.createElement("input", {
1149
- id: "fortune-img-upload",
1150
- type: "file",
1151
- accept: "image/*",
1152
- style: {
1153
- display: "none"
1154
- },
1155
- onChange: function onChange(e) {
1156
- var _a;
1157
- var file = (_a = e.currentTarget.files) === null || _a === void 0 ? void 0 : _a[0];
1158
- if (!file) return;
1159
- var render = new FileReader();
1160
- render.readAsDataURL(file);
1161
- render.onload = function (event) {
1162
- var _a;
1163
- if (event.target == null) return;
1164
- var src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
1165
- var image = new Image();
1166
- image.onload = function () {
1167
- setContext(function (draftCtx) {
1168
- (0, _fortuneCore.insertImage)(draftCtx, image);
1169
- });
1170
- };
1171
- image.src = src;
1172
- };
1173
- e.currentTarget.value = "";
1174
- }
1175
- }));
1146
+ });
1176
1147
  }
1177
1148
  if (name === "comment") {
1178
1149
  var last = (_d = context.luckysheet_select_save) === null || _d === void 0 ? void 0 : _d[context.luckysheet_select_save.length - 1];
@@ -1701,7 +1672,36 @@ var Toolbar = function Toolbar(_a) {
1701
1672
  ref: containerRef,
1702
1673
  className: "fortune-toolbar",
1703
1674
  "aria-label": toolbar.toolbar
1704
- }, /*#__PURE__*/_react.default.createElement("div", {
1675
+ }, /*#__PURE__*/_react.default.createElement(_dataVerificationPortal.default, {
1676
+ visible: showDataValidation
1677
+ }), /*#__PURE__*/_react.default.createElement("input", {
1678
+ id: "fortune-img-upload",
1679
+ type: "file",
1680
+ accept: "image/*",
1681
+ style: {
1682
+ display: "none"
1683
+ },
1684
+ onChange: function onChange(e) {
1685
+ var _a;
1686
+ var file = (_a = e.currentTarget.files) === null || _a === void 0 ? void 0 : _a[0];
1687
+ if (!file) return;
1688
+ var render = new FileReader();
1689
+ render.readAsDataURL(file);
1690
+ render.onload = function (event) {
1691
+ var _a;
1692
+ if (event.target == null) return;
1693
+ var src = (_a = event.target) === null || _a === void 0 ? void 0 : _a.result;
1694
+ var image = new Image();
1695
+ image.onload = function () {
1696
+ setContext(function (draftCtx) {
1697
+ (0, _fortuneCore.insertImage)(draftCtx, image);
1698
+ });
1699
+ };
1700
+ image.src = src;
1701
+ };
1702
+ e.currentTarget.value = "";
1703
+ }
1704
+ }), /*#__PURE__*/_react.default.createElement("div", {
1705
1705
  className: "fortune-toolbar-left"
1706
1706
  }, settings.customToolbarItems.filter(function (n) {
1707
1707
  return n.key === "import-export";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.2.49",
3
+ "version": "1.2.50-patch-2",
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.2.49",
19
+ "@fileverse-dev/fortune-core": "1.2.50-patch-2",
20
20
  "@fileverse/ui": "^4.1.7-patch-40",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",