sense-react-timeline-editor 1.1.5 → 1.1.7

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
@@ -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,
@@ -2908,6 +2908,18 @@ var EditRow = function EditRow(props) {
2908
2908
  uploadBgMusic = props.uploadBgMusic;
2909
2909
  var classNames = ['edit-row'];
2910
2910
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2911
+ var clientWidth = document.documentElement.clientWidth;
2912
+ var timeStart = parserPixelToTime(scrollLeft, {
2913
+ startLeft: startLeft,
2914
+ scale: scale,
2915
+ scaleWidth: scaleWidth
2916
+ });
2917
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2918
+ startLeft: startLeft,
2919
+ scale: scale,
2920
+ scaleWidth: scaleWidth
2921
+ });
2922
+ console.log('time = ', timeStart, ', timeEnd = ', timeEnd);
2911
2923
  var handleTime = function handleTime(e) {
2912
2924
  if (!areaRef.current) return;
2913
2925
  var rect = areaRef.current.getBoundingClientRect();
@@ -2971,7 +2983,9 @@ var EditRow = function EditRow(props) {
2971
2983
  });
2972
2984
  }
2973
2985
  }
2974
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).map(function (action) {
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) {
2975
2989
  return /*#__PURE__*/React.createElement(EditAction, _objectSpread2(_objectSpread2({
2976
2990
  key: action.id
2977
2991
  }, props), {}, {
@@ -3630,7 +3644,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3630
3644
  return /*#__PURE__*/function () {
3631
3645
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(info) {
3632
3646
  var _info$file$response, _info$file;
3633
- var totalDuration, _newAction, uid, duration, newAction;
3647
+ var hasDefault, totalDuration, _newAction, uid, duration, newAction;
3634
3648
  return _regenerator().w(function (_context) {
3635
3649
  while (1) switch (_context.n) {
3636
3650
  case 0:
@@ -3641,11 +3655,36 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3641
3655
  }
3642
3656
  return _context.a(2);
3643
3657
  case 1:
3644
- if (info.file.response) {
3658
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3645
3659
  _context.n = 2;
3646
3660
  break;
3647
3661
  }
3648
- totalDuration = row.actions.reduce(function (max, current) {
3662
+ return _context.a(2, false);
3663
+ case 2:
3664
+ if (!(info.file.status === 'error')) {
3665
+ _context.n = 3;
3666
+ break;
3667
+ }
3668
+ onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3669
+ id: info.file.uid,
3670
+ isUploading: false,
3671
+ start: 0,
3672
+ end: 0,
3673
+ effectId: 'custom_video_effect',
3674
+ isError: true,
3675
+ segment_type: 'bgm',
3676
+ uid: info.file.uid
3677
+ }]);
3678
+ return _context.a(2);
3679
+ case 3:
3680
+ if (info.file.response) {
3681
+ _context.n = 4;
3682
+ break;
3683
+ }
3684
+ hasDefault = row.actions.some(function (action) {
3685
+ return action.id === 'upload-bg-music';
3686
+ });
3687
+ totalDuration = hasDefault ? 0 : row.actions.reduce(function (max, current) {
3649
3688
  var _max$end;
3650
3689
  var currentEnd = current.end || 0;
3651
3690
  var maxEnd = (_max$end = max === null || max === void 0 ? void 0 : max.end) !== null && _max$end !== void 0 ? _max$end : 0;
@@ -3666,11 +3705,11 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3666
3705
  };
3667
3706
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3668
3707
  return _context.a(2);
3669
- case 2:
3708
+ case 4:
3670
3709
  uid = info.file.uid;
3671
- _context.n = 3;
3710
+ _context.n = 5;
3672
3711
  return getAudioDuration(info.file.response.url);
3673
- case 3:
3712
+ case 5:
3674
3713
  duration = _context.v;
3675
3714
  newAction = {
3676
3715
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3685,7 +3724,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3685
3724
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3686
3725
  };
3687
3726
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3688
- case 4:
3727
+ case 6:
3689
3728
  return _context.a(2);
3690
3729
  }
3691
3730
  }, _callee);
@@ -3879,6 +3918,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3879
3918
  backgroundPositionX: "0, ".concat(startLeft, "px"),
3880
3919
  backgroundSize: "".concat(startLeft, "px, ").concat(scaleWidth, "px")
3881
3920
  }),
3921
+ scrollLeft: scrollLeft,
3882
3922
  areaRef: editAreaRef,
3883
3923
  key: key,
3884
3924
  rowHeight: (row === null || row === void 0 ? void 0 : row.rowHeight) || _rowHeight,
@@ -3962,7 +4002,8 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3962
4002
  }).length) > 0,
3963
4003
  customRequest: customRequest,
3964
4004
  onDrop: handleDrop,
3965
- type: "drag"
4005
+ type: "drag",
4006
+ accept: "audio/mp3,audio/wav,audio/mpeg"
3966
4007
  }, tChildren), tChildren ? null : editRow);
3967
4008
  }
3968
4009
  return editRow;
@@ -4020,6 +4061,7 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
4020
4061
  }
4021
4062
  }
4022
4063
  heightRef.current = height;
4064
+ console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4023
4065
  return /*#__PURE__*/React.createElement(Grid, {
4024
4066
  columnCount: 1,
4025
4067
  rowCount: heights.length,
@@ -4212,7 +4254,7 @@ var DragLines = /*#__PURE__*/memo(function (_ref) {
4212
4254
  return /*#__PURE__*/React.createElement("div", {
4213
4255
  className: prefix('drag-line-container'),
4214
4256
  style: {
4215
- height: height || '100%'
4257
+ height: height ? height + 30 : '100%'
4216
4258
  }
4217
4259
  }, isMoving && movePositions.map(function (movePos) {
4218
4260
  // 查找在容差范围内的辅助线位置
@@ -4630,6 +4672,20 @@ var Timeline = /*#__PURE__*/React.forwardRef(function (props, ref) {
4630
4672
  };
4631
4673
  }
4632
4674
  }, []);
4675
+ useEffect(function () {
4676
+ var containerEl = document.querySelector('.timeline-editor');
4677
+ var handleScroll = throttle(function (e) {
4678
+ console.log('scroll', e);
4679
+ scrollSync.current && scrollSync.current.setState({
4680
+ scrollLeft: e.target.scrollLeft || 0
4681
+ });
4682
+ }, 100);
4683
+ containerEl.addEventListener('scroll', handleScroll);
4684
+ return function () {
4685
+ containerEl.removeEventListener('scroll', handleScroll);
4686
+ handleScroll.cancel();
4687
+ };
4688
+ }, []);
4633
4689
  return /*#__PURE__*/React.createElement("div", {
4634
4690
  ref: domRef,
4635
4691
  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,
@@ -2918,6 +2918,18 @@ var EditRow = function EditRow(props) {
2918
2918
  uploadBgMusic = props.uploadBgMusic;
2919
2919
  var classNames = ['edit-row'];
2920
2920
  if (rowData === null || rowData === void 0 ? void 0 : rowData.selected) classNames.push('selected');
2921
+ var clientWidth = document.documentElement.clientWidth;
2922
+ var timeStart = parserPixelToTime(scrollLeft, {
2923
+ startLeft: startLeft,
2924
+ scale: scale,
2925
+ scaleWidth: scaleWidth
2926
+ });
2927
+ var timeEnd = parserPixelToTime(scrollLeft + clientWidth + 200, {
2928
+ startLeft: startLeft,
2929
+ scale: scale,
2930
+ scaleWidth: scaleWidth
2931
+ });
2932
+ console.log('time = ', timeStart, ', timeEnd = ', timeEnd);
2921
2933
  var handleTime = function handleTime(e) {
2922
2934
  if (!areaRef.current) return;
2923
2935
  var rect = areaRef.current.getBoundingClientRect();
@@ -2981,7 +2993,9 @@ var EditRow = function EditRow(props) {
2981
2993
  });
2982
2994
  }
2983
2995
  }
2984
- }, ((rowData === null || rowData === void 0 ? void 0 : rowData.actions) || []).map(function (action) {
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) {
2985
2999
  return /*#__PURE__*/React__default['default'].createElement(EditAction, _objectSpread2(_objectSpread2({
2986
3000
  key: action.id
2987
3001
  }, props), {}, {
@@ -3640,7 +3654,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3640
3654
  return /*#__PURE__*/function () {
3641
3655
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(info) {
3642
3656
  var _info$file$response, _info$file;
3643
- var totalDuration, _newAction, uid, duration, newAction;
3657
+ var hasDefault, totalDuration, _newAction, uid, duration, newAction;
3644
3658
  return _regenerator().w(function (_context) {
3645
3659
  while (1) switch (_context.n) {
3646
3660
  case 0:
@@ -3651,11 +3665,36 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3651
3665
  }
3652
3666
  return _context.a(2);
3653
3667
  case 1:
3654
- if (info.file.response) {
3668
+ if (!(info.file.type !== 'audio/mp3' && info.file.type !== 'audio/wav' && info.file.type !== 'audio/mpeg')) {
3655
3669
  _context.n = 2;
3656
3670
  break;
3657
3671
  }
3658
- totalDuration = row.actions.reduce(function (max, current) {
3672
+ return _context.a(2, false);
3673
+ case 2:
3674
+ if (!(info.file.status === 'error')) {
3675
+ _context.n = 3;
3676
+ break;
3677
+ }
3678
+ onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [{
3679
+ id: info.file.uid,
3680
+ isUploading: false,
3681
+ start: 0,
3682
+ end: 0,
3683
+ effectId: 'custom_video_effect',
3684
+ isError: true,
3685
+ segment_type: 'bgm',
3686
+ uid: info.file.uid
3687
+ }]);
3688
+ return _context.a(2);
3689
+ case 3:
3690
+ if (info.file.response) {
3691
+ _context.n = 4;
3692
+ break;
3693
+ }
3694
+ hasDefault = row.actions.some(function (action) {
3695
+ return action.id === 'upload-bg-music';
3696
+ });
3697
+ totalDuration = hasDefault ? 0 : row.actions.reduce(function (max, current) {
3659
3698
  var _max$end;
3660
3699
  var currentEnd = current.end || 0;
3661
3700
  var maxEnd = (_max$end = max === null || max === void 0 ? void 0 : max.end) !== null && _max$end !== void 0 ? _max$end : 0;
@@ -3676,11 +3715,11 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3676
3715
  };
3677
3716
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [_newAction]);
3678
3717
  return _context.a(2);
3679
- case 2:
3718
+ case 4:
3680
3719
  uid = info.file.uid;
3681
- _context.n = 3;
3720
+ _context.n = 5;
3682
3721
  return getAudioDuration(info.file.response.url);
3683
- case 3:
3722
+ case 5:
3684
3723
  duration = _context.v;
3685
3724
  newAction = {
3686
3725
  id: ((_info$file$response = info.file.response) === null || _info$file$response === void 0 ? void 0 : _info$file$response.id) || uid,
@@ -3695,7 +3734,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3695
3734
  uid: (_info$file = info.file) === null || _info$file === void 0 ? void 0 : _info$file.uid
3696
3735
  };
3697
3736
  onUpdateEditorData === null || onUpdateEditorData === void 0 ? void 0 : onUpdateEditorData(row, [newAction]);
3698
- case 4:
3737
+ case 6:
3699
3738
  return _context.a(2);
3700
3739
  }
3701
3740
  }, _callee);
@@ -3889,6 +3928,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3889
3928
  backgroundPositionX: "0, ".concat(startLeft, "px"),
3890
3929
  backgroundSize: "".concat(startLeft, "px, ").concat(scaleWidth, "px")
3891
3930
  }),
3931
+ scrollLeft: scrollLeft,
3892
3932
  areaRef: editAreaRef,
3893
3933
  key: key,
3894
3934
  rowHeight: (row === null || row === void 0 ? void 0 : row.rowHeight) || _rowHeight,
@@ -3972,7 +4012,8 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3972
4012
  }).length) > 0,
3973
4013
  customRequest: customRequest,
3974
4014
  onDrop: handleDrop,
3975
- type: "drag"
4015
+ type: "drag",
4016
+ accept: "audio/mp3,audio/wav,audio/mpeg"
3976
4017
  }, tChildren), tChildren ? null : editRow);
3977
4018
  }
3978
4019
  return editRow;
@@ -4030,6 +4071,7 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
4030
4071
  }
4031
4072
  }
4032
4073
  heightRef.current = height;
4074
+ console.log('Math.max(scaleCount * scaleWidth + startLeft, width)', Math.max(scaleCount * scaleWidth + startLeft, width), ', width', width);
4033
4075
  return /*#__PURE__*/React__default['default'].createElement(reactVirtualized.Grid, {
4034
4076
  columnCount: 1,
4035
4077
  rowCount: heights.length,
@@ -4222,7 +4264,7 @@ var DragLines = /*#__PURE__*/React.memo(function (_ref) {
4222
4264
  return /*#__PURE__*/React__default['default'].createElement("div", {
4223
4265
  className: prefix('drag-line-container'),
4224
4266
  style: {
4225
- height: height || '100%'
4267
+ height: height ? height + 30 : '100%'
4226
4268
  }
4227
4269
  }, isMoving && movePositions.map(function (movePos) {
4228
4270
  // 查找在容差范围内的辅助线位置
@@ -4640,6 +4682,20 @@ var Timeline = /*#__PURE__*/React__default['default'].forwardRef(function (props
4640
4682
  };
4641
4683
  }
4642
4684
  }, []);
4685
+ React.useEffect(function () {
4686
+ var containerEl = document.querySelector('.timeline-editor');
4687
+ var handleScroll = lodashEs.throttle(function (e) {
4688
+ console.log('scroll', e);
4689
+ scrollSync.current && scrollSync.current.setState({
4690
+ scrollLeft: e.target.scrollLeft || 0
4691
+ });
4692
+ }, 100);
4693
+ containerEl.addEventListener('scroll', handleScroll);
4694
+ return function () {
4695
+ containerEl.removeEventListener('scroll', handleScroll);
4696
+ handleScroll.cancel();
4697
+ };
4698
+ }, []);
4643
4699
  return /*#__PURE__*/React__default['default'].createElement("div", {
4644
4700
  ref: domRef,
4645
4701
  style: style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sense-react-timeline-editor",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "author": "xzdarcy",
5
5
  "license": "MIT",
6
6
  "keywords": [