sense-react-timeline-editor 1.1.6 → 1.1.8

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
@@ -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';
@@ -6,7 +6,7 @@ import interact from 'interactjs';
6
6
  import { useSelectionContainer } from '@air/react-drag-to-select';
7
7
  import { Upload, message } from 'antd/es';
8
8
  import { Howl } from 'howler';
9
- import { groupBy } from 'lodash-es';
9
+ import { groupBy, throttle } from 'lodash-es';
10
10
  import useSize from 'ahooks/es/useSize';
11
11
 
12
12
  function _arrayLikeToArray(r, a) {
@@ -2007,7 +2007,7 @@ var Cursor = function Cursor(_ref) {
2007
2007
  });
2008
2008
  var clientHeight = ((_document$querySelect = document.querySelector("#time-editor-container")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2009
2009
  return /*#__PURE__*/React.createElement(RowDnd, {
2010
- top: theme === 'light' ? 16 : 0,
2010
+ top: theme === 'light' ? 26 : 0,
2011
2011
  start: startLeft,
2012
2012
  height: clientHeight,
2013
2013
  ref: rowRnd,
@@ -2906,8 +2906,48 @@ var EditRow = function EditRow(props) {
2906
2906
  setCursor = props.setCursor,
2907
2907
  hideCursor = props.hideCursor,
2908
2908
  uploadBgMusic = props.uploadBgMusic;
2909
+ var _useState = useState(20),
2910
+ _useState2 = _slicedToArray(_useState, 2),
2911
+ visibleCount = _useState2[0],
2912
+ setVisibleCount = _useState2[1];
2909
2913
  var classNames = ['edit-row'];
2910
2914
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2915
+ var clientWidth = document.documentElement.clientWidth;
2916
+ var timeStart = parserPixelToTime(scrollLeft, {
2917
+ startLeft: startLeft,
2918
+ scale: scale,
2919
+ scaleWidth: scaleWidth
2920
+ });
2921
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2922
+ startLeft: startLeft,
2923
+ scale: scale,
2924
+ scaleWidth: scaleWidth
2925
+ });
2926
+ var visibleActions = useMemo(function () {
2927
+ return ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2928
+ return action.end >= timeStart && action.start <= timeEnd;
2929
+ }).sort(function (a, b) {
2930
+ return a.start - b.start;
2931
+ });
2932
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.actions, timeStart, timeEnd]);
2933
+ var renderActions = useMemo(function () {
2934
+ return visibleActions.slice(0, visibleCount);
2935
+ }, [visibleActions, visibleCount]);
2936
+ useEffect(function () {
2937
+ if (visibleCount < visibleActions.length) {
2938
+ var timer = requestAnimationFrame(function () {
2939
+ setVisibleCount(function (prev) {
2940
+ return Math.min(prev + 20, visibleActions.length);
2941
+ });
2942
+ });
2943
+ return function () {
2944
+ return cancelAnimationFrame(timer);
2945
+ };
2946
+ }
2947
+ }, [visibleCount, visibleActions.length]);
2948
+ useEffect(function () {
2949
+ setVisibleCount(20);
2950
+ }, [scrollLeft, rowData === null || rowData === void 0 ? void 0 : rowData.id]);
2911
2951
  var handleTime = function handleTime(e) {
2912
2952
  if (!areaRef.current) return;
2913
2953
  var rect = areaRef.current.getBoundingClientRect();
@@ -2971,7 +3011,7 @@ var EditRow = function EditRow(props) {
2971
3011
  });
2972
3012
  }
2973
3013
  }
2974
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).map(function (action) {
3014
+ }, renderActions.map(function (action) {
2975
3015
  return /*#__PURE__*/React.createElement(EditAction, _objectSpread2(_objectSpread2({
2976
3016
  key: action.id
2977
3017
  }, props), {}, {
@@ -3641,10 +3681,16 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3641
3681
  }
3642
3682
  return _context.a(2);
3643
3683
  case 1:
3644
- if (!(info.file.status === 'error')) {
3684
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3645
3685
  _context.n = 2;
3646
3686
  break;
3647
3687
  }
3688
+ return _context.a(2, false);
3689
+ case 2:
3690
+ if (!(info.file.status === 'error')) {
3691
+ _context.n = 3;
3692
+ break;
3693
+ }
3648
3694
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3649
3695
  id: info.file.uid,
3650
3696
  isUploading: false,
@@ -3656,9 +3702,9 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3656
3702
  uid: info.file.uid
3657
3703
  }]);
3658
3704
  return _context.a(2);
3659
- case 2:
3705
+ case 3:
3660
3706
  if (info.file.response) {
3661
- _context.n = 3;
3707
+ _context.n = 4;
3662
3708
  break;
3663
3709
  }
3664
3710
  hasDefault = row.actions.some(function (action) {
@@ -3685,11 +3731,11 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3685
3731
  };
3686
3732
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3687
3733
  return _context.a(2);
3688
- case 3:
3734
+ case 4:
3689
3735
  uid = info.file.uid;
3690
- _context.n = 4;
3736
+ _context.n = 5;
3691
3737
  return getAudioDuration(info.file.response.url);
3692
- case 4:
3738
+ case 5:
3693
3739
  duration = _context.v;
3694
3740
  newAction = {
3695
3741
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3704,7 +3750,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3704
3750
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3705
3751
  };
3706
3752
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3707
- case 5:
3753
+ case 6:
3708
3754
  return _context.a(2);
3709
3755
  }
3710
3756
  }, _callee);
@@ -3898,6 +3944,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3898
3944
  backgroundPositionX: "0, ".concat(startLeft, "px"),
3899
3945
  backgroundSize: "".concat(startLeft, "px, ").concat(scaleWidth, "px")
3900
3946
  }),
3947
+ scrollLeft: scrollLeft,
3901
3948
  areaRef: editAreaRef,
3902
3949
  key: key,
3903
3950
  rowHeight: (row === null || row === void 0 ? void 0 : row.rowHeight) || _rowHeight,
@@ -3981,7 +4028,8 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3981
4028
  }).length) > 0,
3982
4029
  customRequest: customRequest,
3983
4030
  onDrop: handleDrop,
3984
- type: "drag"
4031
+ type: "drag",
4032
+ accept: "audio/mp3,audio/wav,audio/mpeg"
3985
4033
  }, tChildren), tChildren ? null : editRow);
3986
4034
  }
3987
4035
  return editRow;
@@ -4039,6 +4087,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
4039
4087
  }
4040
4088
  }
4041
4089
  heightRef.current = height;
4090
+ console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4042
4091
  return /*#__PURE__*/React.createElement(Grid, {
4043
4092
  columnCount: 1,
4044
4093
  rowCount: heights.length,
@@ -4231,7 +4280,7 @@ var DragLines = /*#__PURE__*/memo(function (_ref) {
4231
4280
  return /*#__PURE__*/React.createElement("div", {
4232
4281
  className: prefix('drag-line-container'),
4233
4282
  style: {
4234
- height: height || '100%'
4283
+ height: height ? height + 30 : '100%'
4235
4284
  }
4236
4285
  }, isMoving && movePositions.map(function (movePos) {
4237
4286
  // 查找在容差范围内的辅助线位置
@@ -4649,6 +4698,20 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4649
4698
  };
4650
4699
  }
4651
4700
  }, []);
4701
+ useEffect(function () {
4702
+ var containerEl = document.querySelector('.timeline-editor');
4703
+ var handleScroll = throttle(function (e) {
4704
+ console.log('scroll', e);
4705
+ scrollSync.current && scrollSync.current.setState({
4706
+ scrollLeft: e.target.scrollLeft || 0
4707
+ });
4708
+ }, 100);
4709
+ containerEl.addEventListener('scroll', handleScroll);
4710
+ return function () {
4711
+ containerEl.removeEventListener('scroll', handleScroll);
4712
+ handleScroll.cancel();
4713
+ };
4714
+ }, []);
4652
4715
  return /*#__PURE__*/React.createElement("div", {
4653
4716
  ref: domRef,
4654
4717
  style: style,
package/dist/index.js CHANGED
@@ -2017,7 +2017,7 @@ var Cursor = function Cursor(_ref) {
2017
2017
  });
2018
2018
  var clientHeight = ((_document$querySelect = document.querySelector("#time-editor-container")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientHeight) || 0;
2019
2019
  return /*#__PURE__*/React__default['default'].createElement(RowDnd, {
2020
- top: theme === 'light' ? 16 : 0,
2020
+ top: theme === 'light' ? 26 : 0,
2021
2021
  start: startLeft,
2022
2022
  height: clientHeight,
2023
2023
  ref: rowRnd,
@@ -2916,8 +2916,48 @@ var EditRow = function EditRow(props) {
2916
2916
  setCursor = props.setCursor,
2917
2917
  hideCursor = props.hideCursor,
2918
2918
  uploadBgMusic = props.uploadBgMusic;
2919
+ var _useState = React.useState(20),
2920
+ _useState2 = _slicedToArray(_useState, 2),
2921
+ visibleCount = _useState2[0],
2922
+ setVisibleCount = _useState2[1];
2919
2923
  var classNames = ['edit-row'];
2920
2924
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2925
+ var clientWidth = document.documentElement.clientWidth;
2926
+ var timeStart = parserPixelToTime(scrollLeft, {
2927
+ startLeft: startLeft,
2928
+ scale: scale,
2929
+ scaleWidth: scaleWidth
2930
+ });
2931
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2932
+ startLeft: startLeft,
2933
+ scale: scale,
2934
+ scaleWidth: scaleWidth
2935
+ });
2936
+ var visibleActions = React.useMemo(function () {
2937
+ return ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).filter(function (action) {
2938
+ return action.end >= timeStart && action.start <= timeEnd;
2939
+ }).sort(function (a, b) {
2940
+ return a.start - b.start;
2941
+ });
2942
+ }, [rowData === null || rowData === void 0 ? void 0 : rowData.actions, timeStart, timeEnd]);
2943
+ var renderActions = React.useMemo(function () {
2944
+ return visibleActions.slice(0, visibleCount);
2945
+ }, [visibleActions, visibleCount]);
2946
+ React.useEffect(function () {
2947
+ if (visibleCount < visibleActions.length) {
2948
+ var timer = requestAnimationFrame(function () {
2949
+ setVisibleCount(function (prev) {
2950
+ return Math.min(prev + 20, visibleActions.length);
2951
+ });
2952
+ });
2953
+ return function () {
2954
+ return cancelAnimationFrame(timer);
2955
+ };
2956
+ }
2957
+ }, [visibleCount, visibleActions.length]);
2958
+ React.useEffect(function () {
2959
+ setVisibleCount(20);
2960
+ }, [scrollLeft, rowData === null || rowData === void 0 ? void 0 : rowData.id]);
2921
2961
  var handleTime = function handleTime(e) {
2922
2962
  if (!areaRef.current) return;
2923
2963
  var rect = areaRef.current.getBoundingClientRect();
@@ -2981,7 +3021,7 @@ var EditRow = function EditRow(props) {
2981
3021
  });
2982
3022
  }
2983
3023
  }
2984
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).map(function (action) {
3024
+ }, renderActions.map(function (action) {
2985
3025
  return /*#__PURE__*/React__default['default'].createElement(EditAction, _objectSpread2(_objectSpread2({
2986
3026
  key: action.id
2987
3027
  }, props), {}, {
@@ -3651,10 +3691,16 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3651
3691
  }
3652
3692
  return _context.a(2);
3653
3693
  case 1:
3654
- if (!(info.file.status === 'error')) {
3694
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3655
3695
  _context.n = 2;
3656
3696
  break;
3657
3697
  }
3698
+ return _context.a(2, false);
3699
+ case 2:
3700
+ if (!(info.file.status === 'error')) {
3701
+ _context.n = 3;
3702
+ break;
3703
+ }
3658
3704
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3659
3705
  id: info.file.uid,
3660
3706
  isUploading: false,
@@ -3666,9 +3712,9 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3666
3712
  uid: info.file.uid
3667
3713
  }]);
3668
3714
  return _context.a(2);
3669
- case 2:
3715
+ case 3:
3670
3716
  if (info.file.response) {
3671
- _context.n = 3;
3717
+ _context.n = 4;
3672
3718
  break;
3673
3719
  }
3674
3720
  hasDefault = row.actions.some(function (action) {
@@ -3695,11 +3741,11 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3695
3741
  };
3696
3742
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3697
3743
  return _context.a(2);
3698
- case 3:
3744
+ case 4:
3699
3745
  uid = info.file.uid;
3700
- _context.n = 4;
3746
+ _context.n = 5;
3701
3747
  return getAudioDuration(info.file.response.url);
3702
- case 4:
3748
+ case 5:
3703
3749
  duration = _context.v;
3704
3750
  newAction = {
3705
3751
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3714,7 +3760,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3714
3760
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3715
3761
  };
3716
3762
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3717
- case 5:
3763
+ case 6:
3718
3764
  return _context.a(2);
3719
3765
  }
3720
3766
  }, _callee);
@@ -3908,6 +3954,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3908
3954
  backgroundPositionX: "0, ".concat(startLeft, "px"),
3909
3955
  backgroundSize: "".concat(startLeft, "px, ").concat(scaleWidth, "px")
3910
3956
  }),
3957
+ scrollLeft: scrollLeft,
3911
3958
  areaRef: editAreaRef,
3912
3959
  key: key,
3913
3960
  rowHeight: (row === null || row === void 0 ? void 0 : row.rowHeight) || _rowHeight,
@@ -3991,7 +4038,8 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3991
4038
  }).length) > 0,
3992
4039
  customRequest: customRequest,
3993
4040
  onDrop: handleDrop,
3994
- type: "drag"
4041
+ type: "drag",
4042
+ accept: "audio/mp3,audio/wav,audio/mpeg"
3995
4043
  }, tChildren), tChildren ? null : editRow);
3996
4044
  }
3997
4045
  return editRow;
@@ -4049,6 +4097,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
4049
4097
  }
4050
4098
  }
4051
4099
  heightRef.current = height;
4100
+ console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4052
4101
  return /*#__PURE__*/React__default['default'].createElement(reactVirtualized.Grid, {
4053
4102
  columnCount: 1,
4054
4103
  rowCount: heights.length,
@@ -4241,7 +4290,7 @@ var DragLines = /*#__PURE__*/React.memo(function (_ref) {
4241
4290
  return /*#__PURE__*/React__default['default'].createElement("div", {
4242
4291
  className: prefix('drag-line-container'),
4243
4292
  style: {
4244
- height: height || '100%'
4293
+ height: height ? height + 30 : '100%'
4245
4294
  }
4246
4295
  }, isMoving && movePositions.map(function (movePos) {
4247
4296
  // 查找在容差范围内的辅助线位置
@@ -4659,6 +4708,20 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4659
4708
  };
4660
4709
  }
4661
4710
  }, []);
4711
+ React.useEffect(function () {
4712
+ var containerEl = document.querySelector('.timeline-editor');
4713
+ var handleScroll = lodashEs.throttle(function (e) {
4714
+ console.log('scroll', e);
4715
+ scrollSync.current && scrollSync.current.setState({
4716
+ scrollLeft: e.target.scrollLeft || 0
4717
+ });
4718
+ }, 100);
4719
+ containerEl.addEventListener('scroll', handleScroll);
4720
+ return function () {
4721
+ containerEl.removeEventListener('scroll', handleScroll);
4722
+ handleScroll.cancel();
4723
+ };
4724
+ }, []);
4662
4725
  return /*#__PURE__*/React__default['default'].createElement("div", {
4663
4726
  ref: domRef,
4664
4727
  style: style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sense-react-timeline-editor",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "author": "xzdarcy",
5
5
  "license": "MIT",
6
6
  "keywords": [