sense-react-timeline-editor 1.1.7 → 1.1.9

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.
@@ -1,4 +1,4 @@
1
- import React, { FC } from 'react';
1
+ import React from 'react';
2
2
  import { ScrollSync } from 'react-virtualized';
3
3
  import { CommonProp } from '../../interface/common_prop';
4
4
  import './cursor.less';
@@ -12,11 +12,29 @@ export declare type CursorProps = CommonProp & {
12
12
  left?: number;
13
13
  time?: number;
14
14
  }) => boolean;
15
- /** 时间轴区域dom ref */
15
+ /** 时间轴区域 dom ref */
16
16
  areaRef: React.MutableRefObject<HTMLDivElement>;
17
- /** 设置scroll left */
17
+ /** 设置 scroll left */
18
18
  deltaScrollLeft: (delta: number) => void;
19
- /** 滚动同步ref(TODO: 该数据用于临时解决scrollLeft拖住时不同步问题) */
19
+ /** 滚动同步 ref(TODO: 该数据用于临时解决 scrollLeft 拖住时不同步问题) */
20
20
  scrollSync: React.MutableRefObject<ScrollSync>;
21
21
  };
22
- export declare const Cursor: FC<CursorProps>;
22
+ export interface CursorApi {
23
+ updateLeft: (left: number) => void;
24
+ }
25
+ export declare const Cursor: React.ForwardRefExoticComponent<CommonProp & {
26
+ theme?: string;
27
+ /** 距离左侧滚动距离 */
28
+ scrollLeft: number;
29
+ /** 设置光标位置 */
30
+ setCursor: (param: {
31
+ left?: number;
32
+ time?: number;
33
+ }) => boolean;
34
+ /** 时间轴区域 dom ref */
35
+ areaRef: React.MutableRefObject<HTMLDivElement>;
36
+ /** 设置 scroll left */
37
+ deltaScrollLeft: (delta: number) => void;
38
+ /** 滚动同步 ref(TODO: 该数据用于临时解决 scrollLeft 拖住时不同步问题) */
39
+ scrollSync: React.MutableRefObject<ScrollSync>;
40
+ } & React.RefAttributes<CursorApi>>;
@@ -1,7 +1,8 @@
1
- import { FC } from 'react';
1
+ import React, { FC } from 'react';
2
2
  import { OnScrollParams } from 'react-virtualized';
3
3
  import { CommonProp } from '../../interface/common_prop';
4
4
  import './time_area.less';
5
+ import { CursorApi } from '../cursor/cursor';
5
6
  /** 动画时间轴组件参数 */
6
7
  export declare type TimeAreaProps = CommonProp & {
7
8
  /** 左侧滚动距离 */
@@ -13,6 +14,7 @@ export declare type TimeAreaProps = CommonProp & {
13
14
  left?: number;
14
15
  time?: number;
15
16
  }) => void;
17
+ cursorRef: React.RefObject<CursorApi>;
16
18
  };
17
19
  /** 动画时间轴组件 */
18
20
  export declare const TimeArea: FC<TimeAreaProps>;
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { TimelineEditor, TimelineState } from '../interface/timeline';
3
3
  import './timeline.less';
4
- export declare const Timeline: React.ForwardRefExoticComponent<TimelineEditor & React.RefAttributes<TimelineState>>;
4
+ export declare const Timeline: React.MemoExoticComponent<React.ForwardRefExoticComponent<TimelineEditor & React.RefAttributes<TimelineState>>>;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useRef, useEffect, cloneElement, useImperativeHandle, useState, useLayoutEffect, useCallback, memo, forwardRef, useMemo } from 'react';
1
+ import React, { useRef, useEffect, cloneElement, useImperativeHandle, useState, useLayoutEffect, useCallback, useMemo, memo, forwardRef } from 'react';
2
2
  import { AutoSizer, Grid, ScrollSync } from 'react-virtualized';
3
3
  import { useThrottleEffect, useThrottleFn } from 'ahooks';
4
4
  import { prefixNames } from 'framework-utils';
@@ -1973,26 +1973,38 @@ function styleInject(css, ref) {
1973
1973
  var css_248z = ".timeline-editor-cursor {\n cursor: ew-resize;\n position: absolute;\n top: 32px;\n height: calc(100% - 32px);\n box-sizing: border-box;\n border-left: 1px solid #5297ff;\n border-right: 1px solid #5297ff;\n transform: translateX(-25%) scaleX(0.5);\n transition: transform 0.2s ease-in-out;\n}\n.timeline-editor-cursor-top {\n position: absolute;\n top: 0;\n left: 50%;\n transform: translate(-50%, 0) scaleX(2);\n margin: auto;\n}\n.timeline-editor-cursor-area {\n width: 16px;\n height: 100%;\n cursor: ew-resize;\n position: absolute;\n top: 0;\n left: 50%;\n transform: translateX(-50%);\n}\n.timeline-editor.light .timeline-editor-cursor-top {\n transform: unset;\n position: relative;\n left: 0;\n}\n.timeline-editor.light .timeline-editor-cursor {\n transform: unset;\n display: flex;\n flex-direction: column;\n gap: 2px;\n align-items: center;\n border: none;\n transform: translate(-50%, 0);\n}\n.timeline-editor.light .timeline-editor-cursor-area {\n position: relative;\n border: none;\n width: 10px;\n background-color: transparent;\n transform: unset;\n left: 0;\n transform: translateX(-5px);\n border-right: 1px solid #111;\n}\n";
1974
1974
  styleInject(css_248z);
1975
1975
 
1976
- var Cursor = function Cursor(_ref) {
1976
+ var Cursor = /*#__PURE__*/React.forwardRef(function (props, ref) {
1977
1977
  var _document$querySelect;
1978
- var theme = _ref.theme,
1979
- disableDrag = _ref.disableDrag,
1980
- cursorTime = _ref.cursorTime,
1981
- setCursor = _ref.setCursor,
1982
- startLeft = _ref.startLeft,
1983
- timelineWidth = _ref.timelineWidth,
1984
- scaleWidth = _ref.scaleWidth,
1985
- scale = _ref.scale,
1986
- scrollLeft = _ref.scrollLeft,
1987
- scrollSync = _ref.scrollSync,
1988
- areaRef = _ref.areaRef,
1989
- maxScaleCount = _ref.maxScaleCount,
1990
- deltaScrollLeft = _ref.deltaScrollLeft,
1991
- onCursorDragStart = _ref.onCursorDragStart,
1992
- onCursorDrag = _ref.onCursorDrag,
1993
- onCursorDragEnd = _ref.onCursorDragEnd;
1978
+ var theme = props.theme,
1979
+ disableDrag = props.disableDrag,
1980
+ cursorTime = props.cursorTime,
1981
+ setCursor = props.setCursor,
1982
+ startLeft = props.startLeft,
1983
+ timelineWidth = props.timelineWidth,
1984
+ scaleWidth = props.scaleWidth,
1985
+ scale = props.scale,
1986
+ scrollLeft = props.scrollLeft,
1987
+ scrollSync = props.scrollSync,
1988
+ areaRef = props.areaRef,
1989
+ maxScaleCount = props.maxScaleCount,
1990
+ deltaScrollLeft = props.deltaScrollLeft,
1991
+ onCursorDragStart = props.onCursorDragStart,
1992
+ onCursorDrag = props.onCursorDrag,
1993
+ onCursorDragEnd = props.onCursorDragEnd;
1994
+ console.log('Cursor cursorTime', cursorTime);
1994
1995
  var rowRnd = useRef();
1995
1996
  var draggingLeft = useRef();
1997
+ useImperativeHandle(ref, function () {
1998
+ return {
1999
+ updateLeft: function updateLeft(cursorTime) {
2000
+ rowRnd.current.updateLeft(parserTimeToPixel(cursorTime, {
2001
+ startLeft: startLeft,
2002
+ scaleWidth: scaleWidth,
2003
+ scale: scale
2004
+ }) - scrollLeft);
2005
+ }
2006
+ };
2007
+ });
1996
2008
  useThrottleEffect(function () {
1997
2009
  if (typeof draggingLeft.current === 'undefined') {
1998
2010
  // 非dragging时,根据穿参更新cursor刻度(防抖)
@@ -2005,7 +2017,7 @@ var Cursor = function Cursor(_ref) {
2005
2017
  }, [cursorTime, startLeft, scaleWidth, scale, scrollLeft], {
2006
2018
  wait: 10
2007
2019
  });
2008
- var clientHeight = ((_document$querySelect = document.querySelector("#time-editor-container")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2020
+ var clientHeight = ((_document$querySelect = document.querySelector('#time-editor-container')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2009
2021
  return /*#__PURE__*/React.createElement(RowDnd, {
2010
2022
  top: theme === 'light' ? 26 : 0,
2011
2023
  start: startLeft,
@@ -2040,8 +2052,8 @@ var Cursor = function Cursor(_ref) {
2040
2052
  onCursorDragEnd && onCursorDragEnd(time);
2041
2053
  draggingLeft.current = undefined;
2042
2054
  },
2043
- onDrag: function onDrag(_ref2) {
2044
- var left = _ref2.left;
2055
+ onDrag: function onDrag(_ref) {
2056
+ var left = _ref.left;
2045
2057
  var scroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2046
2058
  var scrollLeft = scrollSync.current.state.scrollLeft;
2047
2059
  if (!scroll || scrollLeft === 0) {
@@ -2080,12 +2092,12 @@ var Cursor = function Cursor(_ref) {
2080
2092
  })), /*#__PURE__*/React.createElement("div", {
2081
2093
  className: prefix('cursor-area')
2082
2094
  })));
2083
- };
2095
+ });
2084
2096
 
2085
2097
  var css_248z$1 = ".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.timeline-editor-selection-box {\n position: fixed;\n border: 2px solid #1890ff;\n background-color: rgba(24, 144, 255, 0.1);\n pointer-events: none;\n z-index: 9999;\n box-shadow: 0 0 8px rgba(24, 144, 255, 0.3);\n left: -100px;\n}\n";
2086
2098
  styleInject(css_248z$1);
2087
2099
 
2088
- var css_248z$2 = ".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[data-action-drag=\"true\"] {\n box-shadow: 0px 8px 8px rgba(77, 54, 41, 0.08);\n border-radius: 34px;\n cursor: pointer;\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";
2100
+ var css_248z$2 = ".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[data-action-drag=\"true\"] {\n box-shadow: 0px 8px 8px rgba(77, 54, 41, 0.08);\n border-radius: 34px;\n cursor: pointer;\n z-index: 100;\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";
2089
2101
  styleInject(css_248z$2);
2090
2102
 
2091
2103
  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";
@@ -2603,6 +2615,7 @@ var EditActionO = function EditActionO(_ref) {
2603
2615
  sourceRowItem.actions = sourceRowItem.actions.filter(function (item) {
2604
2616
  return item.id !== id;
2605
2617
  });
2618
+ actionItem.order = targetRowItem.order;
2606
2619
  // 添加到目标row
2607
2620
  targetRowItem.actions.push(actionItem);
2608
2621
  console.log('Target row actions after:', targetRowItem.actions.length);
@@ -2906,21 +2919,49 @@ var EditRow = function EditRow(props) {
2906
2919
  setCursor = props.setCursor,
2907
2920
  hideCursor = props.hideCursor,
2908
2921
  uploadBgMusic = props.uploadBgMusic;
2922
+ var _useState = useState(20),
2923
+ _useState2 = _slicedToArray(_useState, 2),
2924
+ visibleCount = _useState2[0],
2925
+ setVisibleCount = _useState2[1];
2909
2926
  var classNames = ['edit-row'];
2910
2927
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2911
2928
  var clientWidth = document.documentElement.clientWidth;
2912
- var timeStart = parserPixelToTime(scrollLeft, {
2929
+ var timeStart = parserPixelToTime(scrollLeft - 400, {
2913
2930
  startLeft: startLeft,
2914
2931
  scale: scale,
2915
2932
  scaleWidth: scaleWidth
2916
2933
  });
2917
- var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2934
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 400, {
2918
2935
  startLeft: startLeft,
2919
2936
  scale: scale,
2920
2937
  scaleWidth: scaleWidth
2921
2938
  });
2922
- console.log('time = ', timeStart, ', timeEnd = ', timeEnd);
2923
- var handleTime = function handleTime(e) {
2939
+ var visibleActions = useMemo(function () {
2940
+ return ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2941
+ return action.end >= timeStart && action.start <= timeEnd;
2942
+ }).sort(function (a, b) {
2943
+ return a.start - b.start;
2944
+ });
2945
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.actions, timeStart, timeEnd]);
2946
+ var renderActions = useMemo(function () {
2947
+ return visibleActions.slice(0, visibleCount);
2948
+ }, [visibleActions, visibleCount]);
2949
+ useEffect(function () {
2950
+ if (visibleCount < visibleActions.length) {
2951
+ var timer = requestAnimationFrame(function () {
2952
+ setVisibleCount(function (prev) {
2953
+ return Math.min(prev + 20, visibleActions.length);
2954
+ });
2955
+ });
2956
+ return function () {
2957
+ return cancelAnimationFrame(timer);
2958
+ };
2959
+ }
2960
+ }, [visibleCount, visibleActions.length]);
2961
+ useEffect(function () {
2962
+ setVisibleCount(20);
2963
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.id]);
2964
+ var handleTime = useCallback(function (e) {
2924
2965
  if (!areaRef.current) return;
2925
2966
  var rect = areaRef.current.getBoundingClientRect();
2926
2967
  var position = e.clientX - rect.x;
@@ -2931,7 +2972,7 @@ var EditRow = function EditRow(props) {
2931
2972
  scaleWidth: scaleWidth
2932
2973
  });
2933
2974
  return time;
2934
- };
2975
+ }, [areaRef, scrollLeft, startLeft, scale, scaleWidth]);
2935
2976
  return /*#__PURE__*/React.createElement("div", {
2936
2977
  className: "".concat(prefix.apply(void 0, classNames), " ").concat(((rowData === null || rowData === void 0 ? void 0 : rowData.classNames) || []).join(' ')),
2937
2978
  style: style,
@@ -2983,9 +3024,7 @@ var EditRow = function EditRow(props) {
2983
3024
  });
2984
3025
  }
2985
3026
  }
2986
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2987
- return action.end >= timeStart && action.start <= timeEnd;
2988
- }).map(function (action) {
3027
+ }, renderActions.map(function (action) {
2989
3028
  return /*#__PURE__*/React.createElement(EditAction, _objectSpread2(_objectSpread2({
2990
3029
  key: action.id
2991
3030
  }, props), {}, {
@@ -3373,9 +3412,9 @@ var useRowDrag = function useRowDrag(options) {
3373
3412
  if (up === 0) {
3374
3413
  top = 0;
3375
3414
  } else if (up === 1) {
3376
- top = -20;
3415
+ top = 35;
3377
3416
  } else if (up === -1) {
3378
- top = 20;
3417
+ top = -35;
3379
3418
  }
3380
3419
  // 如果没有初始位置数据,说明不是有效的多选拖拽
3381
3420
  if (!setEditorData || initialPositions.size === 0) {
@@ -3644,7 +3683,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3644
3683
  return /*#__PURE__*/function () {
3645
3684
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(info) {
3646
3685
  var _info$file$response, _info$file;
3647
- var hasDefault, totalDuration, _newAction, uid, duration, newAction;
3686
+ var maxSize, hasDefault, totalDuration, _newAction, uid, duration, newAction;
3648
3687
  return _regenerator().w(function (_context) {
3649
3688
  while (1) switch (_context.n) {
3650
3689
  case 0:
@@ -3655,16 +3694,23 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3655
3694
  }
3656
3695
  return _context.a(2);
3657
3696
  case 1:
3658
- if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3697
+ maxSize = 100 * 1024 * 1024;
3698
+ if (!(info.file.size > maxSize)) {
3659
3699
  _context.n = 2;
3660
3700
  break;
3661
3701
  }
3662
3702
  return _context.a(2, false);
3663
3703
  case 2:
3664
- if (!(info.file.status === 'error')) {
3704
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3665
3705
  _context.n = 3;
3666
3706
  break;
3667
3707
  }
3708
+ return _context.a(2, false);
3709
+ case 3:
3710
+ if (!(info.file.status === 'error')) {
3711
+ _context.n = 4;
3712
+ break;
3713
+ }
3668
3714
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3669
3715
  id: info.file.uid,
3670
3716
  isUploading: false,
@@ -3676,9 +3722,9 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3676
3722
  uid: info.file.uid
3677
3723
  }]);
3678
3724
  return _context.a(2);
3679
- case 3:
3725
+ case 4:
3680
3726
  if (info.file.response) {
3681
- _context.n = 4;
3727
+ _context.n = 5;
3682
3728
  break;
3683
3729
  }
3684
3730
  hasDefault = row.actions.some(function (action) {
@@ -3705,11 +3751,11 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3705
3751
  };
3706
3752
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3707
3753
  return _context.a(2);
3708
- case 4:
3754
+ case 5:
3709
3755
  uid = info.file.uid;
3710
- _context.n = 5;
3756
+ _context.n = 6;
3711
3757
  return getAudioDuration(info.file.response.url);
3712
- case 5:
3758
+ case 6:
3713
3759
  duration = _context.v;
3714
3760
  newAction = {
3715
3761
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3724,7 +3770,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3724
3770
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3725
3771
  };
3726
3772
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3727
- case 6:
3773
+ case 7:
3728
3774
  return _context.a(2);
3729
3775
  }
3730
3776
  }, _callee);
@@ -4061,7 +4107,6 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
4061
4107
  }
4062
4108
  }
4063
4109
  heightRef.current = height;
4064
- console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4065
4110
  return /*#__PURE__*/React.createElement(Grid, {
4066
4111
  columnCount: 1,
4067
4112
  rowCount: heights.length,
@@ -4149,7 +4194,8 @@ var TimeArea = function TimeArea(_ref) {
4149
4194
  scrollLeft = _ref.scrollLeft,
4150
4195
  onClickTimeArea = _ref.onClickTimeArea,
4151
4196
  getScaleRender = _ref.getScaleRender,
4152
- timelineWidth = _ref.timelineWidth;
4197
+ timelineWidth = _ref.timelineWidth,
4198
+ cursorRef = _ref.cursorRef;
4153
4199
  var gridRef = useRef();
4154
4200
  /** 是否显示细分刻度 */
4155
4201
  var showUnit = scaleSplitCount > 0;
@@ -4226,7 +4272,7 @@ var TimeArea = function TimeArea(_ref) {
4226
4272
  scaleWidth: scaleWidth
4227
4273
  });
4228
4274
  var result = onClickTimeArea && onClickTimeArea(time, e);
4229
- if (result === false) return; // 返回false时阻止设置时间
4275
+ if (result === false) return; // 返回 false 时阻止设置时间
4230
4276
  setCursor({
4231
4277
  time: time
4232
4278
  });
@@ -4420,7 +4466,7 @@ var DragLineController = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(function (pro
4420
4466
  }));
4421
4467
  DragLineController.displayName = "DragLineController";
4422
4468
 
4423
- var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4469
+ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (props, ref) {
4424
4470
  var checkedProps = checkProps(props);
4425
4471
  var style = props.style,
4426
4472
  className = props.className,
@@ -4449,6 +4495,7 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4449
4495
  var areaRef = useRef();
4450
4496
  var scrollSync = useRef();
4451
4497
  var containerRef = useRef();
4498
+ var cursorRef = useRef(null);
4452
4499
  console.log(' Timeline mounted = ', areaRef);
4453
4500
  // 编辑器数据
4454
4501
  var _useState = useState(data),
@@ -4501,11 +4548,11 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4501
4548
  scrollTop: scrollTop
4502
4549
  });
4503
4550
  }, [scrollTop]);
4504
- /** 动态设置scale count */
4505
- var handleSetScaleCount = function handleSetScaleCount(value) {
4551
+ /** 动态设置 scale count */
4552
+ var handleSetScaleCount = useCallback(function (value) {
4506
4553
  var data = Math.min(maxScaleCount, Math.max(minScaleCount, value));
4507
4554
  setScaleCount(data);
4508
- };
4555
+ }, [maxScaleCount, minScaleCount]);
4509
4556
  /** 处理主动数据变化 */
4510
4557
  var handleEditorDataChange = function handleEditorDataChange(updatedData) {
4511
4558
  var result = onChange === null || onChange === void 0 ? void 0 : onChange(updatedData);
@@ -4516,7 +4563,7 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4516
4563
  }
4517
4564
  };
4518
4565
  /** 处理光标 */
4519
- var handleSetCursor = function handleSetCursor(param) {
4566
+ var handleSetCursor = useCallback(function (param) {
4520
4567
  var left = param.left,
4521
4568
  time = param.time,
4522
4569
  _param$updateTime = param.updateTime,
@@ -4541,16 +4588,16 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4541
4588
  }
4542
4589
  result && setCursorTime(time);
4543
4590
  return result;
4544
- };
4545
- /** 设置scrollLeft */
4546
- var handleDeltaScrollLeft = function handleDeltaScrollLeft(delta) {
4591
+ }, [startLeft, scale, scaleWidth, autoReRender]);
4592
+ /** 设置 scrollLeft */
4593
+ var handleDeltaScrollLeft = useCallback(function (delta) {
4547
4594
  // 当超过最大距离时,禁止自动滚动
4548
4595
  var data = scrollSync.current.state.scrollLeft + delta;
4549
4596
  if (data > scaleCount * (scaleWidth - 1) + startLeft - width) return;
4550
4597
  scrollSync.current && scrollSync.current.setState({
4551
4598
  scrollLeft: Math.max(scrollSync.current.state.scrollLeft + delta, 0)
4552
4599
  });
4553
- };
4600
+ }, [scaleCount, scaleWidth, startLeft, width]);
4554
4601
  var handleInitDragLine = useCallback(function (data) {
4555
4602
  var _checkedProps$onActio, _checkedProps$onActio2, _dragLineControllerRe;
4556
4603
  (_checkedProps$onActio = checkedProps.onActionMoveStart) === null || _checkedProps$onActio === void 0 ? void 0 : _checkedProps$onActio.call(checkedProps, data);
@@ -4569,6 +4616,10 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4569
4616
  (_checkedProps$onActio6 = checkedProps.onActionResizeEnd) === null || _checkedProps$onActio6 === void 0 ? void 0 : _checkedProps$onActio6.call(checkedProps, data);
4570
4617
  (_dragLineControllerRe3 = dragLineControllerRef.current) === null || _dragLineControllerRe3 === void 0 ? void 0 : _dragLineControllerRe3.disposeDragLine();
4571
4618
  }, [checkedProps]);
4619
+ /** 处理滚动回调 */
4620
+ var onScroll = useCallback(function (params) {
4621
+ onScrollVertical && onScrollVertical(params);
4622
+ }, [onScrollVertical]);
4572
4623
  // 处理运行器相关数据
4573
4624
  useEffect(function () {
4574
4625
  var handleTime = function handleTime(_ref) {
@@ -4641,7 +4692,7 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4641
4692
  }
4642
4693
  };
4643
4694
  });
4644
- var onClickTimeline = function onClickTimeline(e) {
4695
+ var onClickTimeline = useCallback(function (e) {
4645
4696
  var _e$target;
4646
4697
  if (!domRef.current) return;
4647
4698
  var rect = domRef.current.getBoundingClientRect();
@@ -4658,7 +4709,7 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4658
4709
  handleSetCursor({
4659
4710
  time: time
4660
4711
  });
4661
- };
4712
+ }, [startLeft, scale, scaleWidth, hideCursor, handleSetCursor]);
4662
4713
  // 监听timeline区域宽度变化
4663
4714
  useEffect(function () {
4664
4715
  if (areaRef.current) {
@@ -4705,7 +4756,8 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4705
4756
  scaleCount: scaleCount,
4706
4757
  setScaleCount: handleSetScaleCount,
4707
4758
  onScroll: _onScroll,
4708
- scrollLeft: scrollLeft
4759
+ scrollLeft: scrollLeft,
4760
+ cursorRef: cursorRef
4709
4761
  })), areaCount === 1 ? (/*#__PURE__*/React.createElement(EditArea, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
4710
4762
  timelineWidth: width,
4711
4763
  ref: function ref(_ref3) {
@@ -4793,12 +4845,10 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4793
4845
  onActionResizing: handleUpdateDragLine,
4794
4846
  onActionMoveEnd: handleDisposeDragLine,
4795
4847
  onActionResizeEnd: handleDisposeDragLine,
4796
- onScroll: function onScroll(params) {
4797
- _onScroll(params);
4798
- onScrollVertical && onScrollVertical(params);
4799
- }
4848
+ onScroll: _onScroll
4800
4849
  }));
4801
4850
  }))) : null, !hideCursor && (/*#__PURE__*/React.createElement(Cursor, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
4851
+ ref: cursorRef,
4802
4852
  timelineWidth: width,
4803
4853
  disableDrag: isPlaying,
4804
4854
  scrollLeft: scrollLeft,
@@ -4823,6 +4873,6 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4823
4873
  getAssistDragLineActionIds: checkedProps.getAssistDragLineActionIds
4824
4874
  }));
4825
4875
  }));
4826
- });
4876
+ }));
4827
4877
 
4828
4878
  export { Timeline, TimelineEngine };
package/dist/index.js CHANGED
@@ -1983,26 +1983,38 @@ function styleInject(css, ref) {
1983
1983
  var css_248z = ".timeline-editor-cursor {\n cursor: ew-resize;\n position: absolute;\n top: 32px;\n height: calc(100% - 32px);\n box-sizing: border-box;\n border-left: 1px solid #5297ff;\n border-right: 1px solid #5297ff;\n transform: translateX(-25%) scaleX(0.5);\n transition: transform 0.2s ease-in-out;\n}\n.timeline-editor-cursor-top {\n position: absolute;\n top: 0;\n left: 50%;\n transform: translate(-50%, 0) scaleX(2);\n margin: auto;\n}\n.timeline-editor-cursor-area {\n width: 16px;\n height: 100%;\n cursor: ew-resize;\n position: absolute;\n top: 0;\n left: 50%;\n transform: translateX(-50%);\n}\n.timeline-editor.light .timeline-editor-cursor-top {\n transform: unset;\n position: relative;\n left: 0;\n}\n.timeline-editor.light .timeline-editor-cursor {\n transform: unset;\n display: flex;\n flex-direction: column;\n gap: 2px;\n align-items: center;\n border: none;\n transform: translate(-50%, 0);\n}\n.timeline-editor.light .timeline-editor-cursor-area {\n position: relative;\n border: none;\n width: 10px;\n background-color: transparent;\n transform: unset;\n left: 0;\n transform: translateX(-5px);\n border-right: 1px solid #111;\n}\n";
1984
1984
  styleInject(css_248z);
1985
1985
 
1986
- var Cursor = function Cursor(_ref) {
1986
+ var Cursor = /*#__PURE__*/React__default['default'].forwardRef(function (props, ref) {
1987
1987
  var _document$querySelect;
1988
- var theme = _ref.theme,
1989
- disableDrag = _ref.disableDrag,
1990
- cursorTime = _ref.cursorTime,
1991
- setCursor = _ref.setCursor,
1992
- startLeft = _ref.startLeft,
1993
- timelineWidth = _ref.timelineWidth,
1994
- scaleWidth = _ref.scaleWidth,
1995
- scale = _ref.scale,
1996
- scrollLeft = _ref.scrollLeft,
1997
- scrollSync = _ref.scrollSync,
1998
- areaRef = _ref.areaRef,
1999
- maxScaleCount = _ref.maxScaleCount,
2000
- deltaScrollLeft = _ref.deltaScrollLeft,
2001
- onCursorDragStart = _ref.onCursorDragStart,
2002
- onCursorDrag = _ref.onCursorDrag,
2003
- onCursorDragEnd = _ref.onCursorDragEnd;
1988
+ var theme = props.theme,
1989
+ disableDrag = props.disableDrag,
1990
+ cursorTime = props.cursorTime,
1991
+ setCursor = props.setCursor,
1992
+ startLeft = props.startLeft,
1993
+ timelineWidth = props.timelineWidth,
1994
+ scaleWidth = props.scaleWidth,
1995
+ scale = props.scale,
1996
+ scrollLeft = props.scrollLeft,
1997
+ scrollSync = props.scrollSync,
1998
+ areaRef = props.areaRef,
1999
+ maxScaleCount = props.maxScaleCount,
2000
+ deltaScrollLeft = props.deltaScrollLeft,
2001
+ onCursorDragStart = props.onCursorDragStart,
2002
+ onCursorDrag = props.onCursorDrag,
2003
+ onCursorDragEnd = props.onCursorDragEnd;
2004
+ console.log('Cursor cursorTime', cursorTime);
2004
2005
  var rowRnd = React.useRef();
2005
2006
  var draggingLeft = React.useRef();
2007
+ React.useImperativeHandle(ref, function () {
2008
+ return {
2009
+ updateLeft: function updateLeft(cursorTime) {
2010
+ rowRnd.current.updateLeft(parserTimeToPixel(cursorTime, {
2011
+ startLeft: startLeft,
2012
+ scaleWidth: scaleWidth,
2013
+ scale: scale
2014
+ }) - scrollLeft);
2015
+ }
2016
+ };
2017
+ });
2006
2018
  ahooks.useThrottleEffect(function () {
2007
2019
  if (typeof draggingLeft.current === 'undefined') {
2008
2020
  // 非dragging时,根据穿参更新cursor刻度(防抖)
@@ -2015,7 +2027,7 @@ var Cursor = function Cursor(_ref) {
2015
2027
  }, [cursorTime, startLeft, scaleWidth, scale, scrollLeft], {
2016
2028
  wait: 10
2017
2029
  });
2018
- var clientHeight = ((_document$querySelect = document.querySelector("#time-editor-container")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2030
+ var clientHeight = ((_document$querySelect = document.querySelector('#time-editor-container')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2019
2031
  return /*#__PURE__*/React__default['default'].createElement(RowDnd, {
2020
2032
  top: theme === 'light' ? 26 : 0,
2021
2033
  start: startLeft,
@@ -2050,8 +2062,8 @@ var Cursor = function Cursor(_ref) {
2050
2062
  onCursorDragEnd && onCursorDragEnd(time);
2051
2063
  draggingLeft.current = undefined;
2052
2064
  },
2053
- onDrag: function onDrag(_ref2) {
2054
- var left = _ref2.left;
2065
+ onDrag: function onDrag(_ref) {
2066
+ var left = _ref.left;
2055
2067
  var scroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
2056
2068
  var scrollLeft = scrollSync.current.state.scrollLeft;
2057
2069
  if (!scroll || scrollLeft === 0) {
@@ -2090,12 +2102,12 @@ var Cursor = function Cursor(_ref) {
2090
2102
  })), /*#__PURE__*/React__default['default'].createElement("div", {
2091
2103
  className: prefix('cursor-area')
2092
2104
  })));
2093
- };
2105
+ });
2094
2106
 
2095
2107
  var css_248z$1 = ".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.timeline-editor-selection-box {\n position: fixed;\n border: 2px solid #1890ff;\n background-color: rgba(24, 144, 255, 0.1);\n pointer-events: none;\n z-index: 9999;\n box-shadow: 0 0 8px rgba(24, 144, 255, 0.3);\n left: -100px;\n}\n";
2096
2108
  styleInject(css_248z$1);
2097
2109
 
2098
- var css_248z$2 = ".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[data-action-drag=\"true\"] {\n box-shadow: 0px 8px 8px rgba(77, 54, 41, 0.08);\n border-radius: 34px;\n cursor: pointer;\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";
2110
+ var css_248z$2 = ".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[data-action-drag=\"true\"] {\n box-shadow: 0px 8px 8px rgba(77, 54, 41, 0.08);\n border-radius: 34px;\n cursor: pointer;\n z-index: 100;\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";
2099
2111
  styleInject(css_248z$2);
2100
2112
 
2101
2113
  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";
@@ -2613,6 +2625,7 @@ var EditActionO = function EditActionO(_ref) {
2613
2625
  sourceRowItem.actions = sourceRowItem.actions.filter(function (item) {
2614
2626
  return item.id !== id;
2615
2627
  });
2628
+ actionItem.order = targetRowItem.order;
2616
2629
  // 添加到目标row
2617
2630
  targetRowItem.actions.push(actionItem);
2618
2631
  console.log('Target row actions after:', targetRowItem.actions.length);
@@ -2916,21 +2929,49 @@ var EditRow = function EditRow(props) {
2916
2929
  setCursor = props.setCursor,
2917
2930
  hideCursor = props.hideCursor,
2918
2931
  uploadBgMusic = props.uploadBgMusic;
2932
+ var _useState = React.useState(20),
2933
+ _useState2 = _slicedToArray(_useState, 2),
2934
+ visibleCount = _useState2[0],
2935
+ setVisibleCount = _useState2[1];
2919
2936
  var classNames = ['edit-row'];
2920
2937
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2921
2938
  var clientWidth = document.documentElement.clientWidth;
2922
- var timeStart = parserPixelToTime(scrollLeft, {
2939
+ var timeStart = parserPixelToTime(scrollLeft - 400, {
2923
2940
  startLeft: startLeft,
2924
2941
  scale: scale,
2925
2942
  scaleWidth: scaleWidth
2926
2943
  });
2927
- var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2944
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 400, {
2928
2945
  startLeft: startLeft,
2929
2946
  scale: scale,
2930
2947
  scaleWidth: scaleWidth
2931
2948
  });
2932
- console.log('time = ', timeStart, ', timeEnd = ', timeEnd);
2933
- var handleTime = function handleTime(e) {
2949
+ var visibleActions = React.useMemo(function () {
2950
+ return ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2951
+ return action.end >= timeStart && action.start <= timeEnd;
2952
+ }).sort(function (a, b) {
2953
+ return a.start - b.start;
2954
+ });
2955
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.actions, timeStart, timeEnd]);
2956
+ var renderActions = React.useMemo(function () {
2957
+ return visibleActions.slice(0, visibleCount);
2958
+ }, [visibleActions, visibleCount]);
2959
+ React.useEffect(function () {
2960
+ if (visibleCount < visibleActions.length) {
2961
+ var timer = requestAnimationFrame(function () {
2962
+ setVisibleCount(function (prev) {
2963
+ return Math.min(prev + 20, visibleActions.length);
2964
+ });
2965
+ });
2966
+ return function () {
2967
+ return cancelAnimationFrame(timer);
2968
+ };
2969
+ }
2970
+ }, [visibleCount, visibleActions.length]);
2971
+ React.useEffect(function () {
2972
+ setVisibleCount(20);
2973
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.id]);
2974
+ var handleTime = React.useCallback(function (e) {
2934
2975
  if (!areaRef.current) return;
2935
2976
  var rect = areaRef.current.getBoundingClientRect();
2936
2977
  var position = e.clientX - rect.x;
@@ -2941,7 +2982,7 @@ var EditRow = function EditRow(props) {
2941
2982
  scaleWidth: scaleWidth
2942
2983
  });
2943
2984
  return time;
2944
- };
2985
+ }, [areaRef, scrollLeft, startLeft, scale, scaleWidth]);
2945
2986
  return /*#__PURE__*/React__default['default'].createElement("div", {
2946
2987
  className: "".concat(prefix.apply(void 0, classNames), " ").concat(((rowData === null || rowData === void 0 ? void 0 : rowData.classNames) || []).join(' ')),
2947
2988
  style: style,
@@ -2993,9 +3034,7 @@ var EditRow = function EditRow(props) {
2993
3034
  });
2994
3035
  }
2995
3036
  }
2996
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2997
- return action.end >= timeStart && action.start <= timeEnd;
2998
- }).map(function (action) {
3037
+ }, renderActions.map(function (action) {
2999
3038
  return /*#__PURE__*/React__default['default'].createElement(EditAction, _objectSpread2(_objectSpread2({
3000
3039
  key: action.id
3001
3040
  }, props), {}, {
@@ -3383,9 +3422,9 @@ var useRowDrag = function useRowDrag(options) {
3383
3422
  if (up === 0) {
3384
3423
  top = 0;
3385
3424
  } else if (up === 1) {
3386
- top = -20;
3425
+ top = 35;
3387
3426
  } else if (up === -1) {
3388
- top = 20;
3427
+ top = -35;
3389
3428
  }
3390
3429
  // 如果没有初始位置数据,说明不是有效的多选拖拽
3391
3430
  if (!setEditorData || initialPositions.size === 0) {
@@ -3654,7 +3693,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3654
3693
  return /*#__PURE__*/function () {
3655
3694
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(info) {
3656
3695
  var _info$file$response, _info$file;
3657
- var hasDefault, totalDuration, _newAction, uid, duration, newAction;
3696
+ var maxSize, hasDefault, totalDuration, _newAction, uid, duration, newAction;
3658
3697
  return _regenerator().w(function (_context) {
3659
3698
  while (1) switch (_context.n) {
3660
3699
  case 0:
@@ -3665,16 +3704,23 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3665
3704
  }
3666
3705
  return _context.a(2);
3667
3706
  case 1:
3668
- if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3707
+ maxSize = 100 * 1024 * 1024;
3708
+ if (!(info.file.size > maxSize)) {
3669
3709
  _context.n = 2;
3670
3710
  break;
3671
3711
  }
3672
3712
  return _context.a(2, false);
3673
3713
  case 2:
3674
- if (!(info.file.status === 'error')) {
3714
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3675
3715
  _context.n = 3;
3676
3716
  break;
3677
3717
  }
3718
+ return _context.a(2, false);
3719
+ case 3:
3720
+ if (!(info.file.status === 'error')) {
3721
+ _context.n = 4;
3722
+ break;
3723
+ }
3678
3724
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3679
3725
  id: info.file.uid,
3680
3726
  isUploading: false,
@@ -3686,9 +3732,9 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3686
3732
  uid: info.file.uid
3687
3733
  }]);
3688
3734
  return _context.a(2);
3689
- case 3:
3735
+ case 4:
3690
3736
  if (info.file.response) {
3691
- _context.n = 4;
3737
+ _context.n = 5;
3692
3738
  break;
3693
3739
  }
3694
3740
  hasDefault = row.actions.some(function (action) {
@@ -3715,11 +3761,11 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3715
3761
  };
3716
3762
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3717
3763
  return _context.a(2);
3718
- case 4:
3764
+ case 5:
3719
3765
  uid = info.file.uid;
3720
- _context.n = 5;
3766
+ _context.n = 6;
3721
3767
  return getAudioDuration(info.file.response.url);
3722
- case 5:
3768
+ case 6:
3723
3769
  duration = _context.v;
3724
3770
  newAction = {
3725
3771
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3734,7 +3780,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3734
3780
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3735
3781
  };
3736
3782
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3737
- case 6:
3783
+ case 7:
3738
3784
  return _context.a(2);
3739
3785
  }
3740
3786
  }, _callee);
@@ -4071,7 +4117,6 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
4071
4117
  }
4072
4118
  }
4073
4119
  heightRef.current = height;
4074
- console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4075
4120
  return /*#__PURE__*/React__default['default'].createElement(reactVirtualized.Grid, {
4076
4121
  columnCount: 1,
4077
4122
  rowCount: heights.length,
@@ -4159,7 +4204,8 @@ var TimeArea = function TimeArea(_ref) {
4159
4204
  scrollLeft = _ref.scrollLeft,
4160
4205
  onClickTimeArea = _ref.onClickTimeArea,
4161
4206
  getScaleRender = _ref.getScaleRender,
4162
- timelineWidth = _ref.timelineWidth;
4207
+ timelineWidth = _ref.timelineWidth,
4208
+ cursorRef = _ref.cursorRef;
4163
4209
  var gridRef = React.useRef();
4164
4210
  /** 是否显示细分刻度 */
4165
4211
  var showUnit = scaleSplitCount > 0;
@@ -4236,7 +4282,7 @@ var TimeArea = function TimeArea(_ref) {
4236
4282
  scaleWidth: scaleWidth
4237
4283
  });
4238
4284
  var result = onClickTimeArea && onClickTimeArea(time, e);
4239
- if (result === false) return; // 返回false时阻止设置时间
4285
+ if (result === false) return; // 返回 false 时阻止设置时间
4240
4286
  setCursor({
4241
4287
  time: time
4242
4288
  });
@@ -4430,7 +4476,7 @@ var DragLineController = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(f
4430
4476
  }));
4431
4477
  DragLineController.displayName = "DragLineController";
4432
4478
 
4433
- var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props, ref) {
4479
+ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__default['default'].forwardRef(function (props, ref) {
4434
4480
  var checkedProps = checkProps(props);
4435
4481
  var style = props.style,
4436
4482
  className = props.className,
@@ -4459,6 +4505,7 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4459
4505
  var areaRef = React.useRef();
4460
4506
  var scrollSync = React.useRef();
4461
4507
  var containerRef = React.useRef();
4508
+ var cursorRef = React.useRef(null);
4462
4509
  console.log(' Timeline mounted = ', areaRef);
4463
4510
  // 编辑器数据
4464
4511
  var _useState = React.useState(data),
@@ -4511,11 +4558,11 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4511
4558
  scrollTop: scrollTop
4512
4559
  });
4513
4560
  }, [scrollTop]);
4514
- /** 动态设置scale count */
4515
- var handleSetScaleCount = function handleSetScaleCount(value) {
4561
+ /** 动态设置 scale count */
4562
+ var handleSetScaleCount = React.useCallback(function (value) {
4516
4563
  var data = Math.min(maxScaleCount, Math.max(minScaleCount, value));
4517
4564
  setScaleCount(data);
4518
- };
4565
+ }, [maxScaleCount, minScaleCount]);
4519
4566
  /** 处理主动数据变化 */
4520
4567
  var handleEditorDataChange = function handleEditorDataChange(updatedData) {
4521
4568
  var result = onChange === null || onChange === void 0 ? void 0 : onChange(updatedData);
@@ -4526,7 +4573,7 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4526
4573
  }
4527
4574
  };
4528
4575
  /** 处理光标 */
4529
- var handleSetCursor = function handleSetCursor(param) {
4576
+ var handleSetCursor = React.useCallback(function (param) {
4530
4577
  var left = param.left,
4531
4578
  time = param.time,
4532
4579
  _param$updateTime = param.updateTime,
@@ -4551,16 +4598,16 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4551
4598
  }
4552
4599
  result && setCursorTime(time);
4553
4600
  return result;
4554
- };
4555
- /** 设置scrollLeft */
4556
- var handleDeltaScrollLeft = function handleDeltaScrollLeft(delta) {
4601
+ }, [startLeft, scale, scaleWidth, autoReRender]);
4602
+ /** 设置 scrollLeft */
4603
+ var handleDeltaScrollLeft = React.useCallback(function (delta) {
4557
4604
  // 当超过最大距离时,禁止自动滚动
4558
4605
  var data = scrollSync.current.state.scrollLeft + delta;
4559
4606
  if (data > scaleCount * (scaleWidth - 1) + startLeft - width) return;
4560
4607
  scrollSync.current && scrollSync.current.setState({
4561
4608
  scrollLeft: Math.max(scrollSync.current.state.scrollLeft + delta, 0)
4562
4609
  });
4563
- };
4610
+ }, [scaleCount, scaleWidth, startLeft, width]);
4564
4611
  var handleInitDragLine = React.useCallback(function (data) {
4565
4612
  var _checkedProps$onActio, _checkedProps$onActio2, _dragLineControllerRe;
4566
4613
  (_checkedProps$onActio = checkedProps.onActionMoveStart) === null || _checkedProps$onActio === void 0 ? void 0 : _checkedProps$onActio.call(checkedProps, data);
@@ -4579,6 +4626,10 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4579
4626
  (_checkedProps$onActio6 = checkedProps.onActionResizeEnd) === null || _checkedProps$onActio6 === void 0 ? void 0 : _checkedProps$onActio6.call(checkedProps, data);
4580
4627
  (_dragLineControllerRe3 = dragLineControllerRef.current) === null || _dragLineControllerRe3 === void 0 ? void 0 : _dragLineControllerRe3.disposeDragLine();
4581
4628
  }, [checkedProps]);
4629
+ /** 处理滚动回调 */
4630
+ var onScroll = React.useCallback(function (params) {
4631
+ onScrollVertical && onScrollVertical(params);
4632
+ }, [onScrollVertical]);
4582
4633
  // 处理运行器相关数据
4583
4634
  React.useEffect(function () {
4584
4635
  var handleTime = function handleTime(_ref) {
@@ -4651,7 +4702,7 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4651
4702
  }
4652
4703
  };
4653
4704
  });
4654
- var onClickTimeline = function onClickTimeline(e) {
4705
+ var onClickTimeline = React.useCallback(function (e) {
4655
4706
  var _e$target;
4656
4707
  if (!domRef.current) return;
4657
4708
  var rect = domRef.current.getBoundingClientRect();
@@ -4668,7 +4719,7 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4668
4719
  handleSetCursor({
4669
4720
  time: time
4670
4721
  });
4671
- };
4722
+ }, [startLeft, scale, scaleWidth, hideCursor, handleSetCursor]);
4672
4723
  // 监听timeline区域宽度变化
4673
4724
  React.useEffect(function () {
4674
4725
  if (areaRef.current) {
@@ -4715,7 +4766,8 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4715
4766
  scaleCount: scaleCount,
4716
4767
  setScaleCount: handleSetScaleCount,
4717
4768
  onScroll: _onScroll,
4718
- scrollLeft: scrollLeft
4769
+ scrollLeft: scrollLeft,
4770
+ cursorRef: cursorRef
4719
4771
  })), areaCount === 1 ? (/*#__PURE__*/React__default['default'].createElement(EditArea, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
4720
4772
  timelineWidth: width,
4721
4773
  ref: function ref(_ref3) {
@@ -4803,12 +4855,10 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4803
4855
  onActionResizing: handleUpdateDragLine,
4804
4856
  onActionMoveEnd: handleDisposeDragLine,
4805
4857
  onActionResizeEnd: handleDisposeDragLine,
4806
- onScroll: function onScroll(params) {
4807
- _onScroll(params);
4808
- onScrollVertical && onScrollVertical(params);
4809
- }
4858
+ onScroll: _onScroll
4810
4859
  }));
4811
4860
  }))) : null, !hideCursor && (/*#__PURE__*/React__default['default'].createElement(Cursor, _objectSpread2(_objectSpread2({}, checkedProps), {}, {
4861
+ ref: cursorRef,
4812
4862
  timelineWidth: width,
4813
4863
  disableDrag: isPlaying,
4814
4864
  scrollLeft: scrollLeft,
@@ -4833,7 +4883,7 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4833
4883
  getAssistDragLineActionIds: checkedProps.getAssistDragLineActionIds
4834
4884
  }));
4835
4885
  }));
4836
- });
4886
+ }));
4837
4887
 
4838
4888
  exports.Timeline = Timeline;
4839
4889
  exports.TimelineEngine = TimelineEngine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sense-react-timeline-editor",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "author": "xzdarcy",
5
5
  "license": "MIT",
6
6
  "keywords": [