sense-react-timeline-editor 1.0.3 → 1.0.6

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
@@ -2,6 +2,8 @@ import React, { useRef, useEffect, cloneElement, useImperativeHandle, useState,
2
2
  import { AutoSizer, Grid, ScrollSync } from 'react-virtualized';
3
3
  import { prefixNames } from 'framework-utils';
4
4
  import interact from 'interactjs';
5
+ import { Upload, message } from 'antd/es';
6
+ import { Howl } from 'howler';
5
7
  import { groupBy } from 'lodash-es';
6
8
 
7
9
  function _arrayLikeToArray(r, a) {
@@ -19,6 +21,31 @@ function _assertThisInitialized(e) {
19
21
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
20
22
  return e;
21
23
  }
24
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
25
+ try {
26
+ var i = n[a](c),
27
+ u = i.value;
28
+ } catch (n) {
29
+ return void e(n);
30
+ }
31
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
32
+ }
33
+ function _asyncToGenerator(n) {
34
+ return function () {
35
+ var t = this,
36
+ e = arguments;
37
+ return new Promise(function (r, o) {
38
+ var a = n.apply(t, e);
39
+ function _next(n) {
40
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
41
+ }
42
+ function _throw(n) {
43
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
44
+ }
45
+ _next(void 0);
46
+ });
47
+ };
48
+ }
22
49
  function _callSuper(t, o, e) {
23
50
  return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
24
51
  }
@@ -131,6 +158,114 @@ function _possibleConstructorReturn(t, e) {
131
158
  if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
132
159
  return _assertThisInitialized(t);
133
160
  }
161
+ function _regenerator() {
162
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
163
+ var e,
164
+ t,
165
+ r = "function" == typeof Symbol ? Symbol : {},
166
+ n = r.iterator || "@@iterator",
167
+ o = r.toStringTag || "@@toStringTag";
168
+ function i(r, n, o, i) {
169
+ var c = n && n.prototype instanceof Generator ? n : Generator,
170
+ u = Object.create(c.prototype);
171
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
172
+ var i,
173
+ c,
174
+ u,
175
+ f = 0,
176
+ p = o || [],
177
+ y = !1,
178
+ G = {
179
+ p: 0,
180
+ n: 0,
181
+ v: e,
182
+ a: d,
183
+ f: d.bind(e, 4),
184
+ d: function (t, r) {
185
+ return i = t, c = 0, u = e, G.n = r, a;
186
+ }
187
+ };
188
+ function d(r, n) {
189
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
190
+ var o,
191
+ i = p[t],
192
+ d = G.p,
193
+ l = i[2];
194
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
195
+ }
196
+ if (o || r > 1) return a;
197
+ throw y = !0, n;
198
+ }
199
+ return function (o, p, l) {
200
+ if (f > 1) throw TypeError("Generator is already running");
201
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
202
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
203
+ try {
204
+ if (f = 2, i) {
205
+ if (c || (o = "next"), t = i[o]) {
206
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
207
+ if (!t.done) return t;
208
+ u = t.value, c < 2 && (c = 0);
209
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
210
+ i = e;
211
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
212
+ } catch (t) {
213
+ i = e, c = 1, u = t;
214
+ } finally {
215
+ f = 1;
216
+ }
217
+ }
218
+ return {
219
+ value: t,
220
+ done: y
221
+ };
222
+ };
223
+ }(r, o, i), !0), u;
224
+ }
225
+ var a = {};
226
+ function Generator() {}
227
+ function GeneratorFunction() {}
228
+ function GeneratorFunctionPrototype() {}
229
+ t = Object.getPrototypeOf;
230
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
231
+ return this;
232
+ }), t),
233
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
234
+ function f(e) {
235
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
236
+ }
237
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
238
+ return this;
239
+ }), _regeneratorDefine(u, "toString", function () {
240
+ return "[object Generator]";
241
+ }), (_regenerator = function () {
242
+ return {
243
+ w: i,
244
+ m: f
245
+ };
246
+ })();
247
+ }
248
+ function _regeneratorDefine(e, r, n, t) {
249
+ var i = Object.defineProperty;
250
+ try {
251
+ i({}, "", {});
252
+ } catch (e) {
253
+ i = 0;
254
+ }
255
+ _regeneratorDefine = function (e, r, n, t) {
256
+ function o(r, n) {
257
+ _regeneratorDefine(e, r, function (e) {
258
+ return this._invoke(r, n, e);
259
+ });
260
+ }
261
+ r ? i ? i(e, r, {
262
+ value: n,
263
+ enumerable: !t,
264
+ configurable: !t,
265
+ writable: !t
266
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
267
+ }, _regeneratorDefine(e, r, n, t);
268
+ }
134
269
  function _setPrototypeOf(t, e) {
135
270
  return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
136
271
  return t.__proto__ = e, t;
@@ -1102,54 +1237,140 @@ function prefix() {
1102
1237
  return prefixNames.apply(void 0, ["".concat(PREFIX, "-")].concat(classNames));
1103
1238
  }
1104
1239
 
1105
- var DEFAULT_SPEED = 1;
1106
- var MAX_SPEED = 3;
1107
- var CRITICAL_SIZE = 10;
1108
- function useAutoScroll(target) {
1240
+ var DEFAULT_SPEED = 2;
1241
+ var MAX_SPEED = 8;
1242
+ var CRITICAL_SIZE = 5;
1243
+ var EDGE_THRESHOLD = 20; // 距离边缘多少像素开始触发滚动
1244
+ function useAutoScroll(target, verticalScrollTarget) {
1109
1245
  var leftBoundRef = useRef(Number.MIN_SAFE_INTEGER);
1110
1246
  var rightBoundRef = useRef(Number.MAX_SAFE_INTEGER);
1247
+ var topBoundRef = useRef(Number.MIN_SAFE_INTEGER);
1248
+ var bottomBoundRef = useRef(Number.MAX_SAFE_INTEGER);
1111
1249
  var speed = useRef(DEFAULT_SPEED);
1112
1250
  var frame = useRef();
1113
1251
  var initAutoScroll = function initAutoScroll() {
1114
1252
  if (target === null || target === void 0 ? void 0 : target.current) {
1115
1253
  var _target$current$getBo = target.current.getBoundingClientRect(),
1116
1254
  left = _target$current$getBo.left,
1117
- width = _target$current$getBo.width;
1255
+ width = _target$current$getBo.width,
1256
+ top = _target$current$getBo.top,
1257
+ height = _target$current$getBo.height;
1118
1258
  leftBoundRef.current = left;
1119
1259
  rightBoundRef.current = left + width;
1260
+ // Use verticalScrollTarget for Y-axis bounds if provided
1261
+ if (verticalScrollTarget === null || verticalScrollTarget === void 0 ? void 0 : verticalScrollTarget.current) {
1262
+ var verticalRect = verticalScrollTarget.current.getBoundingClientRect();
1263
+ topBoundRef.current = verticalRect.top;
1264
+ bottomBoundRef.current = verticalRect.top + verticalRect.height;
1265
+ } else {
1266
+ topBoundRef.current = top;
1267
+ bottomBoundRef.current = top + height;
1268
+ }
1120
1269
  }
1121
1270
  };
1122
- var dealDragAutoScroll = function dealDragAutoScroll(e, deltaScroll) {
1123
- // 超出
1124
- if (e.clientX >= rightBoundRef.current || e.clientX <= leftBoundRef.current) {
1271
+ var dealDragAutoScroll = function dealDragAutoScroll(e, deltaScroll, deltaScrollTop) {
1272
+ // X轴滚动 - 在边缘附近就开始触发
1273
+ var distanceToRightEdge = rightBoundRef.current - e.clientX;
1274
+ var distanceToLeftEdge = e.clientX - leftBoundRef.current;
1275
+ if (distanceToRightEdge < EDGE_THRESHOLD && distanceToRightEdge > 0) {
1276
+ // 接近右边缘
1125
1277
  cancelAnimationFrame(frame.current);
1126
- var over = Math.abs(e.clientX >= rightBoundRef.current ? e.clientX - rightBoundRef.current : e.clientX - leftBoundRef.current);
1127
- speed.current = Math.min(Number((over / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED, MAX_SPEED);
1128
- var dir = e.clientX >= rightBoundRef.current ? 1 : -1;
1129
- var delta = dir * speed.current;
1278
+ var proximity = EDGE_THRESHOLD - distanceToRightEdge;
1279
+ speed.current = Math.min(Math.max(1, Number((proximity / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1280
+ var delta = speed.current;
1130
1281
  var _loop = function loop() {
1131
1282
  deltaScroll && deltaScroll(delta);
1132
1283
  frame.current = requestAnimationFrame(_loop);
1133
1284
  };
1134
1285
  frame.current = requestAnimationFrame(_loop);
1135
1286
  return false;
1287
+ } else if (distanceToLeftEdge < EDGE_THRESHOLD && distanceToLeftEdge > 0) {
1288
+ // 接近左边缘
1289
+ cancelAnimationFrame(frame.current);
1290
+ var _proximity = EDGE_THRESHOLD - distanceToLeftEdge;
1291
+ speed.current = Math.min(Math.max(1, Number((_proximity / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1292
+ var _delta = -speed.current;
1293
+ var _loop2 = function loop() {
1294
+ deltaScroll && deltaScroll(_delta);
1295
+ frame.current = requestAnimationFrame(_loop2);
1296
+ };
1297
+ frame.current = requestAnimationFrame(_loop2);
1298
+ return false;
1299
+ }
1300
+ // Y轴滚动 - 根据拖拽方向判断
1301
+ else if (deltaScrollTop) {
1302
+ var distanceToBottomEdge = bottomBoundRef.current - e.clientY;
1303
+ var distanceToTopEdge = e.clientY - topBoundRef.current;
1304
+ // console.log('Y-axis check:', {
1305
+ // clientY: e.clientY,
1306
+ // dy: e.dy,
1307
+ // topBound: topBoundRef.current,
1308
+ // bottomBound: bottomBoundRef.current,
1309
+ // distanceToTop: distanceToTopEdge,
1310
+ // distanceToBottom: distanceToBottomEdge,
1311
+ // });
1312
+ // 向下拖拽且接近底部边缘
1313
+ if (e.dy > 0 && distanceToBottomEdge < EDGE_THRESHOLD && distanceToBottomEdge > 0) {
1314
+ // console.log('Triggering BOTTOM scroll (dragging DOWN), delta will be POSITIVE');
1315
+ cancelAnimationFrame(frame.current);
1316
+ var _proximity2 = EDGE_THRESHOLD - distanceToBottomEdge;
1317
+ speed.current = Math.min(Math.max(1, Number((_proximity2 / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1318
+ var _delta2 = speed.current;
1319
+ var _loop3 = function loop() {
1320
+ deltaScrollTop && deltaScrollTop(_delta2);
1321
+ frame.current = requestAnimationFrame(_loop3);
1322
+ };
1323
+ frame.current = requestAnimationFrame(_loop3);
1324
+ return false;
1325
+ }
1326
+ // 向上拖拽且接近顶部边缘
1327
+ else if (e.dy < 0 && distanceToTopEdge < EDGE_THRESHOLD && distanceToTopEdge > 0) {
1328
+ // console.log('Triggering TOP scroll (dragging UP), delta will be NEGATIVE');
1329
+ cancelAnimationFrame(frame.current);
1330
+ var _proximity3 = EDGE_THRESHOLD - distanceToTopEdge;
1331
+ speed.current = Math.min(Math.max(1, Number((_proximity3 / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1332
+ var _delta3 = -speed.current;
1333
+ var _loop4 = function loop() {
1334
+ deltaScrollTop && deltaScrollTop(_delta3);
1335
+ frame.current = requestAnimationFrame(_loop4);
1336
+ };
1337
+ frame.current = requestAnimationFrame(_loop4);
1338
+ return false;
1339
+ } else {
1340
+ cancelAnimationFrame(frame.current);
1341
+ }
1136
1342
  } else {
1137
1343
  cancelAnimationFrame(frame.current);
1138
1344
  }
1139
1345
  return true;
1140
1346
  };
1141
1347
  var dealResizeAutoScroll = function dealResizeAutoScroll(e, dir, deltaScroll) {
1142
- if (e.clientX >= rightBoundRef.current || e.clientX < leftBoundRef.current) {
1348
+ // X轴滚动 - 在边缘附近就开始触发
1349
+ var distanceToRightEdge = rightBoundRef.current - e.clientX;
1350
+ var distanceToLeftEdge = e.clientX - leftBoundRef.current;
1351
+ if (distanceToRightEdge < EDGE_THRESHOLD && distanceToRightEdge > 0) {
1352
+ // 接近右边缘
1143
1353
  cancelAnimationFrame(frame.current);
1144
- var over = Math.abs(e.clientX >= rightBoundRef.current ? e.clientX - rightBoundRef.current : e.clientX - leftBoundRef.current);
1145
- speed.current = Math.min(Number((over / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED, MAX_SPEED);
1146
- var direction = e.clientX >= rightBoundRef.current ? 1 : -1;
1147
- var delta = direction * speed.current;
1148
- var _loop2 = function loop() {
1354
+ var proximity = EDGE_THRESHOLD - distanceToRightEdge;
1355
+ speed.current = Math.min(Math.max(1, Number((proximity / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1356
+ var delta = speed.current;
1357
+ var _loop5 = function loop() {
1149
1358
  deltaScroll && deltaScroll(delta);
1150
- frame.current = requestAnimationFrame(_loop2);
1359
+ frame.current = requestAnimationFrame(_loop5);
1151
1360
  };
1152
- frame.current = requestAnimationFrame(_loop2);
1361
+ frame.current = requestAnimationFrame(_loop5);
1362
+ return false;
1363
+ } else if (distanceToLeftEdge < EDGE_THRESHOLD && distanceToLeftEdge > 0) {
1364
+ // 接近左边缘
1365
+ cancelAnimationFrame(frame.current);
1366
+ var _proximity4 = EDGE_THRESHOLD - distanceToLeftEdge;
1367
+ speed.current = Math.min(Math.max(1, Number((_proximity4 / CRITICAL_SIZE).toFixed(0)) * DEFAULT_SPEED), MAX_SPEED);
1368
+ var _delta4 = -speed.current;
1369
+ var _loop6 = function loop() {
1370
+ deltaScroll && deltaScroll(_delta4);
1371
+ frame.current = requestAnimationFrame(_loop6);
1372
+ };
1373
+ frame.current = requestAnimationFrame(_loop6);
1153
1374
  return false;
1154
1375
  } else {
1155
1376
  cancelAnimationFrame(frame.current);
@@ -1252,12 +1473,14 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1252
1473
  onDragEnd = _ref.onDragEnd,
1253
1474
  onDrag = _ref.onDrag,
1254
1475
  parentRef = _ref.parentRef,
1255
- deltaScrollLeft = _ref.deltaScrollLeft;
1476
+ deltaScrollLeft = _ref.deltaScrollLeft,
1477
+ deltaScrollTop = _ref.deltaScrollTop,
1478
+ verticalScrollRef = _ref.verticalScrollRef;
1256
1479
  var interactable = useRef();
1257
1480
  var deltaX = useRef(0);
1258
1481
  var deltaY = useRef(0);
1259
1482
  var isAdsorption = useRef(false);
1260
- var _useAutoScroll = useAutoScroll(parentRef),
1483
+ var _useAutoScroll = useAutoScroll(parentRef, verticalScrollRef),
1261
1484
  initAutoScroll = _useAutoScroll.initAutoScroll,
1262
1485
  dealDragAutoScroll = _useAutoScroll.dealDragAutoScroll,
1263
1486
  dealResizeAutoScroll = _useAutoScroll.dealResizeAutoScroll,
@@ -1458,14 +1681,33 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1458
1681
  preHeight: preHeight,
1459
1682
  scrollDelta: delta
1460
1683
  });
1461
- });
1684
+ }, deltaScrollTop ? function (delta) {
1685
+ deltaScrollTop(delta);
1686
+ // Y轴自动滚动时,需要累加到 deltaY.current 以保持元素与鼠标的相对位置
1687
+ var _target$dataset6 = target.dataset,
1688
+ left = _target$dataset6.left,
1689
+ width = _target$dataset6.width,
1690
+ top = _target$dataset6.top,
1691
+ height = _target$dataset6.height;
1692
+ var preLeft = parseFloat(left || '0');
1693
+ var preWidth = parseFloat(width || '0');
1694
+ var preTop = parseFloat(top || '0');
1695
+ var preHeight = parseFloat(height || '0');
1696
+ deltaY.current += delta;
1697
+ move({
1698
+ preLeft: preLeft,
1699
+ preWidth: preWidth,
1700
+ preTop: preTop,
1701
+ preHeight: preHeight
1702
+ });
1703
+ } : undefined);
1462
1704
  if (!result) return;
1463
1705
  }
1464
- var _target$dataset6 = target.dataset,
1465
- left = _target$dataset6.left,
1466
- width = _target$dataset6.width,
1467
- top = _target$dataset6.top,
1468
- height = _target$dataset6.height;
1706
+ var _target$dataset7 = target.dataset,
1707
+ left = _target$dataset7.left,
1708
+ width = _target$dataset7.width,
1709
+ top = _target$dataset7.top,
1710
+ height = _target$dataset7.height;
1469
1711
  var preLeft = parseFloat(left || '0');
1470
1712
  var preWidth = parseFloat(width || '0');
1471
1713
  var preTop = parseFloat(top || '0');
@@ -1485,11 +1727,11 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1485
1727
  isAdsorption.current = false;
1486
1728
  stopAutoScroll();
1487
1729
  var target = e.target;
1488
- var _target$dataset7 = target.dataset,
1489
- left = _target$dataset7.left,
1490
- width = _target$dataset7.width,
1491
- top = _target$dataset7.top,
1492
- height = _target$dataset7.height;
1730
+ var _target$dataset8 = target.dataset,
1731
+ left = _target$dataset8.left,
1732
+ width = _target$dataset8.width,
1733
+ top = _target$dataset8.top,
1734
+ height = _target$dataset8.height;
1493
1735
  onDragEnd && onDragEnd({
1494
1736
  left: parseFloat(left),
1495
1737
  width: parseFloat(width),
@@ -1598,9 +1840,9 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1598
1840
  if (deltaScrollLeft && (parentRef === null || parentRef === void 0 ? void 0 : parentRef.current)) {
1599
1841
  var result = dealResizeAutoScroll(e, dir, function (delta) {
1600
1842
  deltaScrollLeft(delta);
1601
- var _target$dataset8 = target.dataset,
1602
- left = _target$dataset8.left,
1603
- width = _target$dataset8.width;
1843
+ var _target$dataset9 = target.dataset,
1844
+ left = _target$dataset9.left,
1845
+ width = _target$dataset9.width;
1604
1846
  var preLeft = parseFloat(left || '0');
1605
1847
  var preWidth = parseFloat(width || '0');
1606
1848
  deltaX.current += delta;
@@ -1612,9 +1854,9 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1612
1854
  });
1613
1855
  if (!result) return;
1614
1856
  }
1615
- var _target$dataset9 = target.dataset,
1616
- left = _target$dataset9.left,
1617
- width = _target$dataset9.width;
1857
+ var _target$dataset0 = target.dataset,
1858
+ left = _target$dataset0.left,
1859
+ width = _target$dataset0.width;
1618
1860
  var preLeft = parseFloat(left || '0');
1619
1861
  var preWidth = parseFloat(width || '0');
1620
1862
  deltaX.current += dir === 'left' ? e.deltaRect.left : e.deltaRect.right;
@@ -1630,9 +1872,9 @@ var RowDnd = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
1630
1872
  isAdsorption.current = false;
1631
1873
  stopAutoScroll();
1632
1874
  var target = e.target;
1633
- var _target$dataset0 = target.dataset,
1634
- left = _target$dataset0.left,
1635
- width = _target$dataset0.width;
1875
+ var _target$dataset1 = target.dataset,
1876
+ left = _target$dataset1.left,
1877
+ width = _target$dataset1.width;
1636
1878
  var dir = ((_e$edges3 = e.edges) === null || _e$edges3 === void 0 ? void 0 : _e$edges3.right) ? 'right' : 'left';
1637
1879
  onResizeEnd && onResizeEnd(dir, {
1638
1880
  left: parseFloat(left),
@@ -1735,7 +1977,7 @@ var Cursor = function Cursor(_ref) {
1735
1977
  }
1736
1978
  }, [cursorTime, startLeft, scaleWidth, scale, scrollLeft]);
1737
1979
  return /*#__PURE__*/React.createElement(RowDnd, {
1738
- top: theme === 'light' ? 40 : 0,
1980
+ top: theme === 'light' ? 16 : 0,
1739
1981
  start: startLeft,
1740
1982
  ref: rowRnd,
1741
1983
  parentRef: areaRef,
@@ -1835,12 +2077,14 @@ var DragLines = function DragLines(_ref) {
1835
2077
  }));
1836
2078
  };
1837
2079
 
1838
- var css_248z$2 = ".timeline-editor:hover .timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar {\n height: 4px;\n}\n.timeline-editor-edit-area {\n flex: 1 1 auto;\n margin-top: 10px;\n overflow: hidden;\n position: relative;\n}\n.timeline-editor-edit-area.no-flex {\n flex: 0 0 auto;\n}\n.timeline-editor-edit-area.overflow-hidden {\n overflow: hidden;\n}\n.timeline-editor-edit-area.overflow-hidden .ReactVirtualized__Grid {\n overflow: hidden !important;\n height: initial !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid {\n outline: none !important;\n overflow: overlay !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar {\n width: 0;\n height: 0;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-track {\n background-color: transparent !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-thumb {\n background: #666;\n border-radius: 16px;\n}\n";
2080
+ var css_248z$2 = ".timeline-editor .ant-upload-wrapper .ant-upload-drag {\n border: none !important;\n background: none !important;\n}\n.timeline-editor:hover .timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar {\n height: 4px;\n}\n.timeline-editor-edit-area {\n flex: 1 1 auto;\n margin-top: 10px;\n overflow: hidden;\n position: relative;\n}\n.timeline-editor-edit-area.no-flex {\n flex: 0 0 auto;\n}\n.timeline-editor-edit-area.overflow-hidden {\n overflow: hidden;\n}\n.timeline-editor-edit-area.overflow-hidden .ReactVirtualized__Grid {\n overflow: hidden !important;\n height: initial !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid {\n outline: none !important;\n overflow: overlay !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar {\n width: 0;\n height: 0;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-track {\n background-color: transparent !important;\n}\n.timeline-editor-edit-area .ReactVirtualized__Grid::-webkit-scrollbar-thumb {\n background: #666;\n border-radius: 16px;\n}\n";
1839
2081
  styleInject(css_248z$2);
1840
2082
 
1841
- var css_248z$3 = ".timeline-editor-action {\n position: absolute;\n left: 0;\n top: 0;\n background-color: #c6cbd2;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch,\n.timeline-editor-action .timeline-editor-action-right-stretch {\n position: absolute;\n top: 0;\n width: 10px;\n border-radius: 4px;\n height: 100%;\n overflow: hidden;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch::after,\n.timeline-editor-action .timeline-editor-action-right-stretch::after {\n position: absolute;\n top: 0;\n bottom: 0;\n margin: auto;\n border-radius: 4px;\n border-top: 28px solid transparent;\n border-bottom: 28px solid transparent;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch {\n left: 0;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch::after {\n left: 0;\n content: \"\";\n border-left: 7px solid rgba(244, 4, 4, 0.202);\n border-right: 7px solid transparent;\n}\n.timeline-editor-action .timeline-editor-action-right-stretch {\n right: 0;\n}\n.timeline-editor-action .timeline-editor-action-right-stretch::after {\n right: 0;\n content: \"\";\n border-right: 7px solid rgba(244, 4, 4, 0.202);\n border-left: 7px solid transparent;\n}\n";
2083
+ var css_248z$3 = ".timeline-editor-action {\n position: absolute;\n left: 0;\n top: 0;\n background-color: #c6cbd2;\n display: flex;\n align-items: center;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch,\n.timeline-editor-action .timeline-editor-action-right-stretch {\n position: absolute;\n}\n.timeline-editor-action .timeline-editor-action-left-stretch {\n left: -3px;\n}\n.timeline-editor-action .timeline-editor-action-right-stretch {\n right: -3px;\n transform: rotate(180deg);\n}\n";
1842
2084
  styleInject(css_248z$3);
1843
2085
 
2086
+ var stretchIcon = "data:image/svg+xml,%3Csvg%20width%3D%227%22%20height%3D%2216%22%20viewBox%3D%220%200%207%2016%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M7%2015C7%2015.5523%206.55228%2016%206%2016L1%2016C0.447715%2016%201.06779e-08%2015.5523%202.38498e-08%2015L3.57746e-07%201C3.70918e-07%200.447715%200.447716%20-1.5627e-07%201%20-1.43099e-07L6%209.29825e-07C6.55229%209.42996e-07%207%200.447716%207%201L7%2015Z%22%20fill%3D%22%23226EFF%22%2F%3E%3Cpath%20d%3D%22M2%204L2%2012%22%20stroke%3D%22white%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3Cpath%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M4%2012.25L5.5%208L4%203.75%22%20fill%3D%22white%22%2F%3E%3Cpath%20d%3D%22M4%2012.25L5.5%208L4%203.75L4%2012.25Z%22%20stroke%3D%22white%22%20stroke-width%3D%220.5%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E";
2087
+
1844
2088
  var EditAction = function EditAction(_ref) {
1845
2089
  var editorData = _ref.editorData,
1846
2090
  row = _ref.row,
@@ -1871,9 +2115,18 @@ var EditAction = function EditAction(_ref) {
1871
2115
  getActionRender = _ref.getActionRender,
1872
2116
  handleTime = _ref.handleTime,
1873
2117
  areaRef = _ref.areaRef,
1874
- deltaScrollLeft = _ref.deltaScrollLeft;
2118
+ deltaScrollLeft = _ref.deltaScrollLeft,
2119
+ _ref$allowCreateTrack = _ref.allowCreateTrack,
2120
+ allowCreateTrack = _ref$allowCreateTrack === void 0 ? true : _ref$allowCreateTrack,
2121
+ setDropPreview = _ref.setDropPreview,
2122
+ containerRef = _ref.containerRef;
1875
2123
  var rowRnd = useRef();
1876
2124
  var isDragWhenClick = useRef(false);
2125
+ var originalPosition = useRef({
2126
+ start: 0,
2127
+ end: 0
2128
+ });
2129
+ var isMounted = useRef(true); // 组件挂载状态
1877
2130
  var id = action.id,
1878
2131
  maxEnd = action.maxEnd,
1879
2132
  minStart = action.minStart,
@@ -1885,6 +2138,17 @@ var EditAction = function EditAction(_ref) {
1885
2138
  _action$movable = action.movable,
1886
2139
  movable = _action$movable === void 0 ? true : _action$movable,
1887
2140
  effectId = action.effectId;
2141
+ var handleDeltaScrollTop = function handleDeltaScrollTop(delta) {
2142
+ if (containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) {
2143
+ containerRef.current.scrollTop += delta * 2;
2144
+ }
2145
+ };
2146
+ // 组件卸载时清理
2147
+ useEffect(function () {
2148
+ return function () {
2149
+ isMounted.current = false;
2150
+ };
2151
+ }, []);
1888
2152
  // 获取最大/最小 像素范围
1889
2153
  var leftLimit = parserTimeToPixel(minStart || 0, {
1890
2154
  startLeft: startLeft,
@@ -1945,6 +2209,11 @@ var EditAction = function EditAction(_ref) {
1945
2209
  };
1946
2210
  //#region [rgba(100,120,156,0.08)] 回调
1947
2211
  var handleDragStart = function handleDragStart() {
2212
+ // 保存原始位置
2213
+ originalPosition.current = {
2214
+ start: action.start,
2215
+ end: action.end
2216
+ };
1948
2217
  onActionMoveStart && onActionMoveStart({
1949
2218
  action: action,
1950
2219
  row: row
@@ -1955,6 +2224,34 @@ var EditAction = function EditAction(_ref) {
1955
2224
  width = _ref2.width,
1956
2225
  top = _ref2.top;
1957
2226
  isDragWhenClick.current = true;
2227
+ // 检查是否需要显示预览指示器
2228
+ if (allowCreateTrack && setDropPreview && top !== undefined) {
2229
+ var _currentRowIndex = editorData.findIndex(function (item) {
2230
+ return item.id === row.id;
2231
+ });
2232
+ var rowHeightValue = rowHeight || 32;
2233
+ // 添加阈值,避免边界处频繁切换
2234
+ var threshold = 0.2; // 降低阈值,使预览指示器更灵敏
2235
+ var preciseOffset = top / rowHeightValue;
2236
+ var preciseIndex = _currentRowIndex + preciseOffset;
2237
+ // 判断是否需要显示预览指示器
2238
+ if (preciseIndex < -threshold) {
2239
+ // 拖拽到顶部之前
2240
+ setDropPreview({
2241
+ position: 'before',
2242
+ rowIndex: 0
2243
+ });
2244
+ } else if (preciseIndex >= editorData.length - 1 + threshold) {
2245
+ // 拖拽到底部之后
2246
+ setDropPreview({
2247
+ position: 'after',
2248
+ rowIndex: editorData.length - 1
2249
+ });
2250
+ } else {
2251
+ // 在现有轨道范围内,不显示预览
2252
+ setDropPreview(null);
2253
+ }
2254
+ }
1958
2255
  if (onActionMoving) {
1959
2256
  var _parserTransformToTim = parserTransformToTime({
1960
2257
  left: left,
@@ -1974,11 +2271,13 @@ var EditAction = function EditAction(_ref) {
1974
2271
  });
1975
2272
  if (result === false) return false;
1976
2273
  }
1977
- setTransform({
1978
- left: left,
1979
- width: width,
1980
- top: top || 0
1981
- });
2274
+ if (isMounted.current) {
2275
+ setTransform({
2276
+ left: left,
2277
+ width: width,
2278
+ top: top || 0
2279
+ });
2280
+ }
1982
2281
  handleScaleCount(left, width);
1983
2282
  };
1984
2283
  var handleDragEnd = function handleDragEnd(_ref3) {
@@ -1986,6 +2285,10 @@ var EditAction = function EditAction(_ref) {
1986
2285
  width = _ref3.width,
1987
2286
  top = _ref3.top,
1988
2287
  height = _ref3.height;
2288
+ // 清理预览指示器
2289
+ if (setDropPreview) {
2290
+ setDropPreview(null);
2291
+ }
1989
2292
  // 计算时间
1990
2293
  var _parserTransformToTim2 = parserTransformToTime({
1991
2294
  left: left,
@@ -2001,20 +2304,72 @@ var EditAction = function EditAction(_ref) {
2001
2304
  var targetRowIndex = editorData.findIndex(function (item) {
2002
2305
  return item.id === row.id;
2003
2306
  });
2307
+ var needCreateNewRow = false;
2308
+ var newRowPosition = 'after';
2004
2309
  if (top !== undefined && height !== undefined) {
2005
2310
  // 通过Y轴位置计算目标row的索引
2006
- var currentRowIndex = editorData.findIndex(function (item) {
2311
+ var _currentRowIndex2 = editorData.findIndex(function (item) {
2007
2312
  return item.id === row.id;
2008
2313
  });
2009
2314
  var rowHeightValue = rowHeight || 32; // 使用默认行高或传入的行高
2010
- var rowOffset = Math.round(top / rowHeightValue);
2011
- targetRowIndex = Math.max(0, Math.min(currentRowIndex + rowOffset, editorData.length - 1));
2315
+ // 使用与预览指示器相同的阈值逻辑
2316
+ var threshold = 0.2;
2317
+ var preciseOffset = top / rowHeightValue;
2318
+ var preciseIndex = _currentRowIndex2 + preciseOffset;
2319
+ // 检查是否需要创建新轨道
2320
+ if (allowCreateTrack) {
2321
+ if (preciseIndex < -threshold) {
2322
+ // 拖拽到第一个轨道之前,需要在前面创建新轨道
2323
+ needCreateNewRow = true;
2324
+ newRowPosition = 'before';
2325
+ targetRowIndex = 0;
2326
+ } else if (preciseIndex >= editorData.length - 1 + threshold) {
2327
+ // 拖拽到最后一个轨道之后,需要在后面创建新轨道
2328
+ needCreateNewRow = true;
2329
+ newRowPosition = 'after';
2330
+ targetRowIndex = editorData.length;
2331
+ } else {
2332
+ // 在现有轨道范围内,使用四舍五入找到最近的轨道
2333
+ var rowOffset = Math.round(preciseOffset);
2334
+ targetRowIndex = Math.max(0, Math.min(_currentRowIndex2 + rowOffset, editorData.length - 1));
2335
+ }
2336
+ } else {
2337
+ // 不允许创建新轨道时,限制在现有轨道范围内
2338
+ var _rowOffset = Math.round(preciseOffset);
2339
+ targetRowIndex = Math.max(0, Math.min(_currentRowIndex2 + _rowOffset, editorData.length - 1));
2340
+ }
2012
2341
  }
2013
2342
  // 设置数据
2014
2343
  var sourceRowItem = editorData.find(function (item) {
2015
2344
  return item.id === row.id;
2016
2345
  });
2017
- var targetRowItem = editorData[targetRowIndex];
2346
+ var targetRowItem;
2347
+ // 如果需要创建新轨道
2348
+ if (needCreateNewRow) {
2349
+ var newRowId = "row_".concat(Date.now(), "_").concat(Math.random().toString(36).substr(2, 9));
2350
+ targetRowItem = {
2351
+ id: newRowId,
2352
+ actions: [],
2353
+ rowHeight: rowHeight,
2354
+ type: row.type,
2355
+ classNames: row.classNames,
2356
+ canUpload: row.canUpload // 继承源轨道的canUpload属性
2357
+ };
2358
+ console.log('Creating new row:', newRowId, 'with type:', row.type);
2359
+ // 将新轨道插入到正确的位置
2360
+ if (newRowPosition === 'before') {
2361
+ editorData.unshift(targetRowItem);
2362
+ targetRowIndex = 0;
2363
+ console.log('New row inserted at beginning, index:', targetRowIndex);
2364
+ } else {
2365
+ editorData.push(targetRowItem);
2366
+ targetRowIndex = editorData.length - 1;
2367
+ console.log('New row inserted at end, index:', targetRowIndex);
2368
+ }
2369
+ } else {
2370
+ targetRowItem = editorData[targetRowIndex];
2371
+ console.log('Using existing row:', targetRowItem.id, 'at index:', targetRowIndex);
2372
+ }
2018
2373
  var actionItem = sourceRowItem.actions.find(function (item) {
2019
2374
  return item.id === id;
2020
2375
  });
@@ -2080,7 +2435,15 @@ var EditAction = function EditAction(_ref) {
2080
2435
  var candidateStart = candidateEnd - duration;
2081
2436
  var distance = Math.abs(candidateStart - start);
2082
2437
  console.log('Candidate before first action:', candidateStart, '-', candidateEnd, 'distance:', distance);
2083
- if (distance < minDistance) {
2438
+ if (candidateStart < 0) {
2439
+ return {
2440
+ start: start,
2441
+ end: end,
2442
+ found: false
2443
+ };
2444
+ }
2445
+ // 检查候选位置的 start 是否小于 0
2446
+ if (candidateStart >= 0 && distance < minDistance) {
2084
2447
  minDistance = distance;
2085
2448
  bestPosition = {
2086
2449
  start: candidateStart,
@@ -2154,8 +2517,17 @@ var EditAction = function EditAction(_ref) {
2154
2517
  // 执行碰撞检测和调整
2155
2518
  var adjustmentResult = checkAndAdjustCollision();
2156
2519
  if (!adjustmentResult.found) {
2157
- // 如果找不到合适位置,取消移动
2158
- console.warn('Cannot find suitable position, cancelling move');
2520
+ // 如果找不到合适位置,回到原始位置
2521
+ console.warn('Cannot find suitable position, reverting to original position');
2522
+ // 恢复原始位置的transform
2523
+ var originalTransform = parserTimeToTransform(originalPosition.current, {
2524
+ startLeft: startLeft,
2525
+ scale: scale,
2526
+ scaleWidth: scaleWidth
2527
+ });
2528
+ setTransform(_objectSpread2(_objectSpread2({}, originalTransform), {}, {
2529
+ top: 0
2530
+ }));
2159
2531
  return;
2160
2532
  }
2161
2533
  // 使用调整后的时间
@@ -2167,12 +2539,29 @@ var EditAction = function EditAction(_ref) {
2167
2539
  actionItem.end = end;
2168
2540
  // 如果拖拽到了不同的row,需要移动action
2169
2541
  if (targetRowItem.id !== row.id) {
2542
+ console.log('Moving action to different row');
2543
+ console.log('Source row:', row.id, 'Target row:', targetRowItem.id);
2544
+ console.log('Is new row:', needCreateNewRow);
2545
+ console.log('Target row actions before:', targetRowItem.actions.length);
2170
2546
  // 从原row中移除
2171
2547
  sourceRowItem.actions = sourceRowItem.actions.filter(function (item) {
2172
2548
  return item.id !== id;
2173
2549
  });
2174
2550
  // 添加到目标row
2175
2551
  targetRowItem.actions.push(actionItem);
2552
+ console.log('Target row actions after:', targetRowItem.actions.length);
2553
+ console.log('Action added:', actionItem.id);
2554
+ // 如果源轨道没有action了,删除源轨道
2555
+ if (sourceRowItem.actions.length === 0) {
2556
+ console.log('Source row is empty, removing it:', sourceRowItem.id);
2557
+ var sourceRowIndex = editorData.findIndex(function (item) {
2558
+ return item.id === sourceRowItem.id;
2559
+ });
2560
+ if (sourceRowIndex !== -1) {
2561
+ editorData.splice(sourceRowIndex, 1);
2562
+ console.log('Source row removed at index:', sourceRowIndex);
2563
+ }
2564
+ }
2176
2565
  }
2177
2566
  setEditorData(_toConsumableArray(editorData));
2178
2567
  // 更新transform以反映新位置
@@ -2192,7 +2581,8 @@ var EditAction = function EditAction(_ref) {
2192
2581
  action: actionItem,
2193
2582
  row: targetRowItem,
2194
2583
  start: start,
2195
- end: end
2584
+ end: end,
2585
+ isNewRow: needCreateNewRow
2196
2586
  });
2197
2587
  };
2198
2588
  var handleResizeStart = function handleResizeStart(dir) {
@@ -2281,9 +2671,13 @@ var EditAction = function EditAction(_ref) {
2281
2671
  if (row.actions.includes(action)) {
2282
2672
  nowRow.actions[row.actions.indexOf(action)] = nowAction;
2283
2673
  }
2674
+ var currentRowIndex = editorData.findIndex(function (item) {
2675
+ return item.id === row.id;
2676
+ });
2284
2677
  return /*#__PURE__*/React.createElement(RowDnd, {
2285
2678
  ref: rowRnd,
2286
2679
  parentRef: areaRef,
2680
+ verticalScrollRef: containerRef,
2287
2681
  start: startLeft,
2288
2682
  left: transform.left,
2289
2683
  width: transform.width,
@@ -2295,12 +2689,8 @@ var EditAction = function EditAction(_ref) {
2295
2689
  bounds: {
2296
2690
  left: leftLimit,
2297
2691
  right: rightLimit,
2298
- top: -editorData.findIndex(function (item) {
2299
- return item.id === row.id;
2300
- }) * rowHeight,
2301
- bottom: (editorData.length - editorData.findIndex(function (item) {
2302
- return item.id === row.id;
2303
- })) * rowHeight
2692
+ top: -(currentRowIndex + 1) * rowHeight,
2693
+ bottom: (editorData.length - currentRowIndex + 1) * rowHeight
2304
2694
  },
2305
2695
  edges: {
2306
2696
  left: !disableDrag && flexible && ".".concat(prefix('action-left-stretch')),
@@ -2314,7 +2704,8 @@ var EditAction = function EditAction(_ref) {
2314
2704
  onResizeStart: handleResizeStart,
2315
2705
  onResize: handleResizing,
2316
2706
  onResizeEnd: handleResizeEnd,
2317
- deltaScrollLeft: deltaScrollLeft
2707
+ deltaScrollLeft: deltaScrollLeft,
2708
+ deltaScrollTop: handleDeltaScrollTop
2318
2709
  }, /*#__PURE__*/React.createElement("div", {
2319
2710
  onMouseDown: function onMouseDown() {
2320
2711
  isDragWhenClick.current = false;
@@ -2364,12 +2755,18 @@ var EditAction = function EditAction(_ref) {
2364
2755
  }
2365
2756
  }, getActionRender && getActionRender(nowAction, nowRow), flexible && /*#__PURE__*/React.createElement("div", {
2366
2757
  className: prefix('action-left-stretch')
2367
- }), flexible && /*#__PURE__*/React.createElement("div", {
2758
+ }, /*#__PURE__*/React.createElement("img", {
2759
+ src: stretchIcon,
2760
+ alt: ""
2761
+ })), flexible && /*#__PURE__*/React.createElement("div", {
2368
2762
  className: prefix('action-right-stretch')
2369
- })));
2763
+ }, /*#__PURE__*/React.createElement("img", {
2764
+ src: stretchIcon,
2765
+ alt: ""
2766
+ }))));
2370
2767
  };
2371
2768
 
2372
- var css_248z$4 = ".timeline-editor-edit-row {\n background-repeat: no-repeat, repeat;\n display: flex;\n flex-direction: row;\n box-sizing: border-box;\n}\n";
2769
+ var css_248z$4 = ".timeline-editor-edit-row {\n background-repeat: no-repeat, repeat;\n display: flex;\n flex-direction: row;\n box-sizing: border-box;\n}\n.timeline-editor-edit-row.preview-row {\n background-color: rgba(100, 150, 255, 0.15);\n border: 1px dashed rgba(100, 150, 255, 0.5);\n opacity: 0.8;\n transition: all 0.2s ease;\n}\n";
2373
2770
  styleInject(css_248z$4);
2374
2771
 
2375
2772
  var EditRow = function EditRow(props) {
@@ -2383,7 +2780,9 @@ var EditRow = function EditRow(props) {
2383
2780
  scrollLeft = props.scrollLeft,
2384
2781
  startLeft = props.startLeft,
2385
2782
  scale = props.scale,
2386
- scaleWidth = props.scaleWidth;
2783
+ scaleWidth = props.scaleWidth,
2784
+ allowCreateTrack = props.allowCreateTrack,
2785
+ containerRef = props.containerRef;
2387
2786
  var classNames = ['edit-row'];
2388
2787
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('edit-row-selected');
2389
2788
  var handleTime = function handleTime(e) {
@@ -2434,7 +2833,10 @@ var EditRow = function EditRow(props) {
2434
2833
  }, props), {}, {
2435
2834
  handleTime: handleTime,
2436
2835
  row: rowData,
2437
- action: action
2836
+ action: action,
2837
+ allowCreateTrack: allowCreateTrack,
2838
+ setDropPreview: props.setDropPreview,
2839
+ containerRef: containerRef
2438
2840
  }));
2439
2841
  }));
2440
2842
  };
@@ -2545,6 +2947,22 @@ function useDragLine() {
2545
2947
  };
2546
2948
  }
2547
2949
 
2950
+ // 获取音频时长
2951
+ var getAudioDuration = function getAudioDuration(url) {
2952
+ return new Promise(function (resolve) {
2953
+ var sound = new Howl({
2954
+ src: [url]
2955
+ });
2956
+ sound.on('load', function () {
2957
+ resolve(sound.duration());
2958
+ sound.unload();
2959
+ });
2960
+ sound.on('loaderror', function () {
2961
+ resolve(2); // 加载失败时返回默认时长2秒
2962
+ sound.unload();
2963
+ });
2964
+ });
2965
+ };
2548
2966
  var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2549
2967
  var className = props.className,
2550
2968
  _props$isMulti = props.isMulti,
@@ -2567,7 +2985,61 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2567
2985
  _onActionMoving = props.onActionMoving,
2568
2986
  _onActionResizeEnd = props.onActionResizeEnd,
2569
2987
  _onActionResizeStart = props.onActionResizeStart,
2570
- _onActionResizing = props.onActionResizing;
2988
+ _onActionResizing = props.onActionResizing,
2989
+ onUpdateEditorData = props.onUpdateEditorData,
2990
+ _props$canUpload = props.canUpload,
2991
+ canUpload = _props$canUpload === void 0 ? false : _props$canUpload,
2992
+ customRequest = props.customRequest,
2993
+ setEditorData = props.setEditorData,
2994
+ _props$allowCreateTra = props.allowCreateTrack,
2995
+ allowCreateTrack = _props$allowCreateTra === void 0 ? true : _props$allowCreateTra,
2996
+ containerRef = props.containerRef;
2997
+ // 支持mp3\wav格式上传
2998
+ var onBeforeUpload = function onBeforeUpload(file) {
2999
+ if (file.type !== 'audio/mp3' && file.type !== 'audio/wav') {
3000
+ message.error('只能上传mp3wav格式的音频');
3001
+ return false;
3002
+ }
3003
+ return true;
3004
+ };
3005
+ var handleUploadChange = function handleUploadChange(row) {
3006
+ return /*#__PURE__*/function () {
3007
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(info) {
3008
+ var uid, duration, newAction;
3009
+ return _regenerator().w(function (_context) {
3010
+ while (1) switch (_context.n) {
3011
+ case 0:
3012
+ console.log('Upload info:', info);
3013
+ if (!(!info.file || !info.file.response)) {
3014
+ _context.n = 1;
3015
+ break;
3016
+ }
3017
+ return _context.a(2);
3018
+ case 1:
3019
+ uid = info.file.uid;
3020
+ _context.n = 2;
3021
+ return getAudioDuration(info.file.response.url);
3022
+ case 2:
3023
+ duration = _context.v;
3024
+ newAction = {
3025
+ id: uid,
3026
+ effectId: 'custom_video_effect',
3027
+ flexible: true,
3028
+ url: info.file.response.url,
3029
+ start: currentMouseTime,
3030
+ end: currentMouseTime + duration
3031
+ };
3032
+ onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3033
+ case 3:
3034
+ return _context.a(2);
3035
+ }
3036
+ }, _callee);
3037
+ }));
3038
+ return function (_x) {
3039
+ return _ref.apply(this, arguments);
3040
+ };
3041
+ }();
3042
+ };
2571
3043
  var _useDragLine = useDragLine(),
2572
3044
  dragLineData = _useDragLine.dragLineData,
2573
3045
  initDragLine = _useDragLine.initDragLine,
@@ -2577,7 +3049,33 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2577
3049
  defaultGetMovePosition = _useDragLine.defaultGetMovePosition;
2578
3050
  var editAreaRef = useRef();
2579
3051
  var gridRef = useRef();
3052
+ var _useState = useState(0),
3053
+ _useState2 = _slicedToArray(_useState, 2),
3054
+ currentMouseTime = _useState2[0],
3055
+ setCurrentMouseTime = _useState2[1];
2580
3056
  var heightRef = useRef(-1);
3057
+ var uploadRef = useRef();
3058
+ var _useState3 = useState(null),
3059
+ _useState4 = _slicedToArray(_useState3, 2),
3060
+ dropPreview = _useState4[0],
3061
+ setDropPreview = _useState4[1];
3062
+ // 处理拖拽上传事件
3063
+ var handleDrop = function handleDrop(e) {
3064
+ e.preventDefault();
3065
+ e.stopPropagation();
3066
+ // 计算鼠标所在位置的时间
3067
+ if (!editAreaRef.current) return;
3068
+ var rect = editAreaRef.current.getBoundingClientRect();
3069
+ var position = e.clientX - rect.x;
3070
+ var left = position + scrollLeft;
3071
+ var time = parserPixelToTime(left, {
3072
+ startLeft: startLeft,
3073
+ scale: scale,
3074
+ scaleWidth: scaleWidth
3075
+ });
3076
+ setCurrentMouseTime(time);
3077
+ console.log('拖拽上传位置的时间:', time);
3078
+ };
2581
3079
  // ref 数据
2582
3080
  useImperativeHandle(ref, function () {
2583
3081
  return {
@@ -2627,12 +3125,12 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2627
3125
  }
2628
3126
  };
2629
3127
  /** 获取每个cell渲染内容 */
2630
- var cellRenderer = function cellRenderer(_ref) {
2631
- var rowIndex = _ref.rowIndex,
2632
- key = _ref.key,
2633
- style = _ref.style;
3128
+ var cellRenderer = function cellRenderer(_ref2) {
3129
+ var rowIndex = _ref2.rowIndex,
3130
+ key = _ref2.key,
3131
+ style = _ref2.style;
2634
3132
  var row = editorData[rowIndex]; // 行数据
2635
- return /*#__PURE__*/React.createElement(EditRow, _objectSpread2(_objectSpread2({}, props), {}, {
3133
+ var editRow = /*#__PURE__*/React.createElement(EditRow, _objectSpread2(_objectSpread2({}, props), {}, {
2636
3134
  style: _objectSpread2(_objectSpread2({}, style), {}, {
2637
3135
  backgroundPositionX: "0, ".concat(startLeft, "px"),
2638
3136
  backgroundSize: "".concat(startLeft, "px, ").concat(scaleWidth, "px")
@@ -2642,6 +3140,9 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2642
3140
  rowHeight: (row === null || row === void 0 ? void 0 : row.rowHeight) || _rowHeight,
2643
3141
  rowData: row,
2644
3142
  dragLineData: dragLineData,
3143
+ allowCreateTrack: allowCreateTrack,
3144
+ setDropPreview: setDropPreview,
3145
+ containerRef: containerRef,
2645
3146
  onActionMoveStart: function onActionMoveStart(data) {
2646
3147
  handleInitDragLine(data);
2647
3148
  return _onActionMoveStart && _onActionMoveStart(data);
@@ -2667,6 +3168,26 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2667
3168
  return _onActionMoveEnd && _onActionMoveEnd(data);
2668
3169
  }
2669
3170
  }));
3171
+ if (canUpload || (row === null || row === void 0 ? void 0 : row.canUpload)) {
3172
+ return /*#__PURE__*/React.createElement(Upload, {
3173
+ ref: uploadRef,
3174
+ key: key,
3175
+ style: _objectSpread2(_objectSpread2({
3176
+ width: '100%',
3177
+ display: 'block'
3178
+ }, style), {}, {
3179
+ top: 0
3180
+ }),
3181
+ beforeUpload: onBeforeUpload,
3182
+ onChange: handleUploadChange(row),
3183
+ showUploadList: false,
3184
+ openFileDialogOnClick: false,
3185
+ customRequest: customRequest,
3186
+ onDrop: handleDrop,
3187
+ type: "drag"
3188
+ }, editRow);
3189
+ }
3190
+ return editRow;
2670
3191
  };
2671
3192
  useLayoutEffect(function () {
2672
3193
  var _gridRef$current;
@@ -2680,7 +3201,7 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2680
3201
  }, [editorData]);
2681
3202
  var _totalHeight = editorData.reduce(function (prev, cur) {
2682
3203
  return prev + (cur.rowHeight || _rowHeight);
2683
- }, 0) + 32;
3204
+ }, 0) + ((className || '').indexOf('1') > -1 ? 12 : 32);
2684
3205
  return /*#__PURE__*/React.createElement("div", {
2685
3206
  ref: editAreaRef,
2686
3207
  className: prefix('edit-area') + " ".concat((className || '').replace('timeline-editor', '') || ''),
@@ -2692,9 +3213,9 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2692
3213
  style: {
2693
3214
  height: isMulti ? _totalHeight : 'unset'
2694
3215
  }
2695
- }, function (_ref2) {
2696
- var width = _ref2.width,
2697
- height = _ref2.height;
3216
+ }, function (_ref3) {
3217
+ var width = _ref3.width,
3218
+ height = _ref3.height;
2698
3219
  // 获取全部高度
2699
3220
  var totalHeight = 0;
2700
3221
  // 高度列表
@@ -2723,26 +3244,50 @@ var EditArea = /*#__PURE__*/React.forwardRef(function (props, ref) {
2723
3244
  columnWidth: Math.max(scaleCount * scaleWidth + startLeft, width),
2724
3245
  width: width,
2725
3246
  height: height,
2726
- rowHeight: function rowHeight(_ref3) {
2727
- var index = _ref3.index;
3247
+ rowHeight: function rowHeight(_ref4) {
3248
+ var index = _ref4.index;
2728
3249
  return heights[index] || _rowHeight;
2729
3250
  },
2730
3251
  overscanRowCount: 10,
2731
3252
  overscanColumnCount: 0,
2732
3253
  onScroll: function onScroll(param) {
2733
- console.log(param, 'onScroll');
2734
3254
  _onScroll(param);
2735
3255
  }
2736
3256
  });
2737
3257
  }), dragLine && /*#__PURE__*/React.createElement(DragLines, _objectSpread2({
2738
3258
  scrollLeft: scrollLeft
2739
- }, dragLineData)));
3259
+ }, dragLineData)), dropPreview && function () {
3260
+ // 计算预览指示器的位置
3261
+ var top = 0;
3262
+ for (var i = 0; i < editorData.length; i++) {
3263
+ if (dropPreview.position === 'before' && i === dropPreview.rowIndex) {
3264
+ break;
3265
+ }
3266
+ top += editorData[i].rowHeight || _rowHeight;
3267
+ if (dropPreview.position === 'after' && i === dropPreview.rowIndex) {
3268
+ break;
3269
+ }
3270
+ }
3271
+ return /*#__PURE__*/React.createElement("div", {
3272
+ style: {
3273
+ position: 'absolute',
3274
+ left: 0,
3275
+ right: 0,
3276
+ top: top - scrollTop,
3277
+ height: '2px',
3278
+ backgroundColor: 'transparent',
3279
+ borderTop: '2px dashed #1890ff',
3280
+ zIndex: 1000,
3281
+ pointerEvents: 'none'
3282
+ }
3283
+ });
3284
+ }());
2740
3285
  });
2741
3286
 
2742
3287
  var css_248z$5 = ".timeline-editor {\n height: 600px;\n width: 600px;\n min-height: 32px;\n position: relative;\n font-size: 12px;\n font-family: \"PingFang SC\";\n background-color: #191b1d;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n}\n.timeline-editor.light {\n background-color: #fff;\n}\n";
2743
3288
  styleInject(css_248z$5);
2744
3289
 
2745
- var css_248z$6 = ".timeline-editor-time-area {\n position: relative;\n height: 32px;\n flex: 0 0 auto;\n}\n.timeline-editor-time-area .ReactVirtualized__Grid {\n outline: none;\n}\n.timeline-editor-time-area .ReactVirtualized__Grid::-webkit-scrollbar {\n display: none;\n}\n.timeline-editor-time-area-interact {\n position: absolute;\n cursor: pointer;\n left: 0;\n top: 0;\n}\n.timeline-editor-time-unit {\n border-right: 1px solid rgba(255, 255, 255, 0.2);\n position: relative;\n box-sizing: content-box;\n height: 4px !important;\n bottom: 0 !important;\n top: auto !important;\n}\n.timeline-editor-time-unit-big {\n height: 8px !important;\n}\n.timeline-editor-time-unit-scale {\n color: rgba(255, 255, 255, 0.6);\n position: absolute;\n right: 0;\n top: 0;\n transform: translate(50%, -100%);\n}\n.light.timeline-editor .timeline-editor-time-unit {\n border-color: #666;\n}\n.light.timeline-editor .timeline-editor-time-unit-scale {\n color: #111;\n}\n";
3290
+ var css_248z$6 = ".timeline-editor-time-area {\n position: relative;\n height: 32px;\n flex: 0 0 auto;\n}\n.timeline-editor-time-area .ReactVirtualized__Grid {\n outline: none;\n}\n.timeline-editor-time-area .ReactVirtualized__Grid::-webkit-scrollbar {\n display: none;\n}\n.timeline-editor-time-area-interact {\n position: absolute;\n cursor: pointer;\n left: 0;\n top: 0;\n}\n.timeline-editor-time-unit {\n border-right: 1px solid rgba(255, 255, 255, 0.2);\n position: relative;\n box-sizing: content-box;\n height: 4px !important;\n bottom: 0 !important;\n top: auto !important;\n}\n.timeline-editor-time-unit-big {\n height: 8px !important;\n}\n.timeline-editor-time-unit-scale {\n color: rgba(255, 255, 255, 0.6);\n position: absolute;\n right: 0;\n top: 0;\n transform: translate(50%, -100%);\n}\n.light.timeline-editor .timeline-editor-time-unit {\n border-color: #111;\n}\n.light.timeline-editor .timeline-editor-time-unit-scale {\n color: #666;\n}\n";
2746
3291
  styleInject(css_248z$6);
2747
3292
 
2748
3293
  /** 动画时间轴组件 */
@@ -2859,11 +3404,14 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
2859
3404
  engine = checkedProps.engine,
2860
3405
  _checkedProps$autoReR = checkedProps.autoReRender,
2861
3406
  autoReRender = _checkedProps$autoReR === void 0 ? true : _checkedProps$autoReR,
2862
- onScrollVertical = checkedProps.onScroll;
3407
+ onScrollVertical = checkedProps.onScroll,
3408
+ _checkedProps$allowCr = checkedProps.allowCreateTrack,
3409
+ allowCreateTrack = _checkedProps$allowCr === void 0 ? true : _checkedProps$allowCr;
2863
3410
  var engineRef = useRef(engine || new TimelineEngine());
2864
3411
  var domRef = useRef();
2865
3412
  var areaRef = useRef();
2866
3413
  var scrollSync = useRef();
3414
+ var containerRef = useRef();
2867
3415
  // 编辑器数据
2868
3416
  var _useState = useState(data),
2869
3417
  _useState2 = _slicedToArray(_useState, 2),
@@ -3070,11 +3618,18 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
3070
3618
  scrollLeft: scrollLeft,
3071
3619
  setEditorData: handleEditorDataChange,
3072
3620
  deltaScrollLeft: autoScroll && handleDeltaScrollLeft,
3621
+ allowCreateTrack: allowCreateTrack,
3073
3622
  onScroll: function onScroll(params) {
3074
3623
  _onScroll(params);
3075
3624
  onScrollVertical && onScrollVertical(params);
3076
3625
  }
3077
- }))) : null, areaCount > 1 ? Object.keys(groupedData).map(function (key, index) {
3626
+ }))) : null, areaCount > 1 ? /*#__PURE__*/React.createElement("div", {
3627
+ id: 'time-editor-container',
3628
+ ref: containerRef,
3629
+ style: {
3630
+ overflow: 'auto'
3631
+ }
3632
+ }, Object.keys(groupedData).map(function (key, index) {
3078
3633
  var handleGroupDataChange = function handleGroupDataChange(updatedData) {
3079
3634
  var mergedData = editorData.filter(function (item) {
3080
3635
  return String(item.type) !== key;
@@ -3093,9 +3648,9 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
3093
3648
  };
3094
3649
  return /*#__PURE__*/React.createElement(EditArea, _objectSpread2(_objectSpread2({
3095
3650
  key: key,
3096
- isMulti: areaCount > 1,
3097
- className: index !== 0 ? "no-flex ".concat(key, " ").concat(index) : "overflow-hidden ".concat(key, " ").concat(index)
3651
+ isMulti: areaCount > 1
3098
3652
  }, checkedProps), {}, {
3653
+ className: index !== 0 ? "no-flex ".concat(key, " ").concat(index) : "overflow-hidden ".concat(key, " ").concat(index),
3099
3654
  timelineWidth: width,
3100
3655
  ref: function ref(_ref4) {
3101
3656
  return areaRef.current = _ref4 === null || _ref4 === void 0 ? void 0 : _ref4.domRef.current;
@@ -3109,12 +3664,14 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
3109
3664
  scrollLeft: scrollLeft,
3110
3665
  setEditorData: handleGroupDataChange,
3111
3666
  deltaScrollLeft: autoScroll && handleDeltaScrollLeft,
3667
+ allowCreateTrack: allowCreateTrack,
3668
+ containerRef: containerRef,
3112
3669
  onScroll: function onScroll(params) {
3113
3670
  _onScroll(params);
3114
3671
  onScrollVertical && onScrollVertical(params);
3115
3672
  }
3116
3673
  }));
3117
- }) : null, !hideCursor && (/*#__PURE__*/React.createElement(Cursor, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
3674
+ })) : null, !hideCursor && (/*#__PURE__*/React.createElement(Cursor, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
3118
3675
  timelineWidth: width,
3119
3676
  disableDrag: isPlaying,
3120
3677
  scrollLeft: scrollLeft,