sense-react-timeline-editor 1.1.32 → 1.1.34

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
@@ -3890,20 +3890,35 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
3890
3890
  if (trackPreviewDataRef.current) setTrackPreview(trackPreviewDataRef.current);
3891
3891
  if (dragIndicatorDataRef.current) setDragIndicator(dragIndicatorDataRef.current);
3892
3892
  }, [scrollTop]);
3893
+ // 使用 ref 追踪 handleSelectionChange 的调用深度,避免无限循环
3894
+ var selectionChangeDepthRef = useRef(0);
3893
3895
  // 框选功能
3894
3896
  var handleSelectionChange = useCallback(function (selectedActionIds) {
3895
- // 更新 editorData 中每个 action 的选中状态
3896
- var updatedData = editorData.map(function (row) {
3897
- return _objectSpread2(_objectSpread2({}, row), {}, {
3898
- actions: row.actions.map(function (action) {
3899
- return _objectSpread2(_objectSpread2({}, action), {}, {
3900
- selected: selectedActionIds.includes(action.id)
3901
- });
3902
- })
3897
+ // 如果调用深度过深(超过10层),说明可能存在无限循环,直接返回
3898
+ if (selectionChangeDepthRef.current > 10) {
3899
+ console.warn('Selection change depth exceeded, possible infinite loop detected');
3900
+ return;
3901
+ }
3902
+ selectionChangeDepthRef.current++;
3903
+ try {
3904
+ // 更新 editorData 中每个 action 的选中状态
3905
+ var updatedData = editorData.map(function (row) {
3906
+ return _objectSpread2(_objectSpread2({}, row), {}, {
3907
+ actions: row.actions.map(function (action) {
3908
+ return _objectSpread2(_objectSpread2({}, action), {}, {
3909
+ selected: selectedActionIds.includes(action.id)
3910
+ });
3911
+ })
3912
+ });
3903
3913
  });
3904
- });
3905
- setEditorData(updatedData);
3906
- onMutiSelectChange === null || onMutiSelectChange === void 0 ? void 0 : onMutiSelectChange(selectedActionIds);
3914
+ setEditorData(updatedData);
3915
+ onMutiSelectChange === null || onMutiSelectChange === void 0 ? void 0 : onMutiSelectChange(selectedActionIds);
3916
+ } finally {
3917
+ // 延迟重置计数器,确保在 React 完成渲染后执行
3918
+ setTimeout(function () {
3919
+ selectionChangeDepthRef.current--;
3920
+ }, 0);
3921
+ }
3907
3922
  }, [editorData, setEditorData, onMutiSelectChange]);
3908
3923
  var _useRowSelection = useRowSelection({
3909
3924
  editorData: editorData,
@@ -4173,8 +4188,9 @@ var EditAreaO = /*#__PURE__*/React.forwardRef(function (props, ref) {
4173
4188
  };
4174
4189
  }, [engineRef, uploadBgMusic, editorData]);
4175
4190
  var _totalHeight = editorData.reduce(function (prev, cur) {
4176
- return prev + (cur.rowHeight || _rowHeight);
4191
+ return prev + (cur.rowHeight + 2 || _rowHeight);
4177
4192
  }, 0) + ((className || '').indexOf('1') > -1 ? 12 : 32);
4193
+ // console.log(_totalHeight, ', editorData = ', editorData);
4178
4194
  if (minHeight) {
4179
4195
  var calcHeight = "calc(100% - ".concat(minHeight + 16, "px)");
4180
4196
  _totalHeight = "max(".concat(_totalHeight, "px, ").concat(calcHeight, ")");
@@ -4786,8 +4802,19 @@ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (p
4786
4802
  useEffect(function () {
4787
4803
  var handleClickOutside = function handleClickOutside(e) {
4788
4804
  var target = e.target;
4789
- var actionEl = target.closest('.timeline-editor-time-area') || target.closest('.timeline-editor-action');
4790
- if (actionEl) return;
4805
+ var areaEl = target.closest('.timeline-editor-time-area');
4806
+ if (areaEl) return;
4807
+ var actionEl = target.closest('.timeline-editor-action');
4808
+ if (actionEl) {
4809
+ var _props$onClickActionO;
4810
+ // @ts-expect-error 类型断言
4811
+ (_props$onClickActionO = props.onClickActionOnly) === null || _props$onClickActionO === void 0 ? void 0 : _props$onClickActionO.call(props, e, {
4812
+ action: {
4813
+ id: actionEl.dataset.actionId
4814
+ }
4815
+ });
4816
+ return;
4817
+ }
4791
4818
  engineRef.current.trigger('mousedown', {
4792
4819
  target: target,
4793
4820
  evt: e
@@ -4803,7 +4830,7 @@ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (p
4803
4830
  return function () {
4804
4831
  document.removeEventListener('mousedown', handleClickOutside);
4805
4832
  };
4806
- }, []);
4833
+ }, [props.onClickActionOnly]);
4807
4834
  // ref 数据
4808
4835
  useImperativeHandle(ref, function () {
4809
4836
  return {
@@ -4927,6 +4954,9 @@ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (p
4927
4954
  handleScroll.cancel();
4928
4955
  };
4929
4956
  }, [startLeft, scale, scaleWidth]);
4957
+ var _totalHeight = editorData.reduce(function (prev, cur) {
4958
+ return prev + (cur.rowHeight + 2 || 32);
4959
+ }, 0) + 32 + 24;
4930
4960
  return /*#__PURE__*/React.createElement("div", {
4931
4961
  ref: domRef,
4932
4962
  style: style,
@@ -4980,7 +5010,7 @@ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (p
4980
5010
  id: "time-editor-container",
4981
5011
  ref: containerRef,
4982
5012
  style: {
4983
- height: '100%',
5013
+ height: _totalHeight,
4984
5014
  background: '#fff'
4985
5015
  },
4986
5016
  onClick: throttledOnClickTimeline
@@ -5026,7 +5056,7 @@ var Timeline = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function (p
5026
5056
  setCursor: handleSetCursor,
5027
5057
  deltaScrollLeft: autoScroll && handleDeltaScrollLeft,
5028
5058
  allowCreateTrack: allowCreateTrack,
5029
- minHeight: index === 0 ? 122 : _totalHeight,
5059
+ minHeight: index === 0 ? 122 : undefined,
5030
5060
  containerRef: containerRef,
5031
5061
  onMutiSelectChange: props === null || props === void 0 ? void 0 : props.onMutiSelectChange,
5032
5062
  engineRef: engineRef,
package/dist/index.js CHANGED
@@ -3900,20 +3900,35 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
3900
3900
  if (trackPreviewDataRef.current) setTrackPreview(trackPreviewDataRef.current);
3901
3901
  if (dragIndicatorDataRef.current) setDragIndicator(dragIndicatorDataRef.current);
3902
3902
  }, [scrollTop]);
3903
+ // 使用 ref 追踪 handleSelectionChange 的调用深度,避免无限循环
3904
+ var selectionChangeDepthRef = React.useRef(0);
3903
3905
  // 框选功能
3904
3906
  var handleSelectionChange = React.useCallback(function (selectedActionIds) {
3905
- // 更新 editorData 中每个 action 的选中状态
3906
- var updatedData = editorData.map(function (row) {
3907
- return _objectSpread2(_objectSpread2({}, row), {}, {
3908
- actions: row.actions.map(function (action) {
3909
- return _objectSpread2(_objectSpread2({}, action), {}, {
3910
- selected: selectedActionIds.includes(action.id)
3911
- });
3912
- })
3907
+ // 如果调用深度过深(超过10层),说明可能存在无限循环,直接返回
3908
+ if (selectionChangeDepthRef.current > 10) {
3909
+ console.warn('Selection change depth exceeded, possible infinite loop detected');
3910
+ return;
3911
+ }
3912
+ selectionChangeDepthRef.current++;
3913
+ try {
3914
+ // 更新 editorData 中每个 action 的选中状态
3915
+ var updatedData = editorData.map(function (row) {
3916
+ return _objectSpread2(_objectSpread2({}, row), {}, {
3917
+ actions: row.actions.map(function (action) {
3918
+ return _objectSpread2(_objectSpread2({}, action), {}, {
3919
+ selected: selectedActionIds.includes(action.id)
3920
+ });
3921
+ })
3922
+ });
3913
3923
  });
3914
- });
3915
- setEditorData(updatedData);
3916
- onMutiSelectChange === null || onMutiSelectChange === void 0 ? void 0 : onMutiSelectChange(selectedActionIds);
3924
+ setEditorData(updatedData);
3925
+ onMutiSelectChange === null || onMutiSelectChange === void 0 ? void 0 : onMutiSelectChange(selectedActionIds);
3926
+ } finally {
3927
+ // 延迟重置计数器,确保在 React 完成渲染后执行
3928
+ setTimeout(function () {
3929
+ selectionChangeDepthRef.current--;
3930
+ }, 0);
3931
+ }
3917
3932
  }, [editorData, setEditorData, onMutiSelectChange]);
3918
3933
  var _useRowSelection = useRowSelection({
3919
3934
  editorData: editorData,
@@ -4183,8 +4198,9 @@ var EditAreaO = /*#__PURE__*/React__default['default'].forwardRef(function (prop
4183
4198
  };
4184
4199
  }, [engineRef, uploadBgMusic, editorData]);
4185
4200
  var _totalHeight = editorData.reduce(function (prev, cur) {
4186
- return prev + (cur.rowHeight || _rowHeight);
4201
+ return prev + (cur.rowHeight + 2 || _rowHeight);
4187
4202
  }, 0) + ((className || '').indexOf('1') > -1 ? 12 : 32);
4203
+ // console.log(_totalHeight, ', editorData = ', editorData);
4188
4204
  if (minHeight) {
4189
4205
  var calcHeight = "calc(100% - ".concat(minHeight + 16, "px)");
4190
4206
  _totalHeight = "max(".concat(_totalHeight, "px, ").concat(calcHeight, ")");
@@ -4796,8 +4812,19 @@ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__d
4796
4812
  React.useEffect(function () {
4797
4813
  var handleClickOutside = function handleClickOutside(e) {
4798
4814
  var target = e.target;
4799
- var actionEl = target.closest('.timeline-editor-time-area') || target.closest('.timeline-editor-action');
4800
- if (actionEl) return;
4815
+ var areaEl = target.closest('.timeline-editor-time-area');
4816
+ if (areaEl) return;
4817
+ var actionEl = target.closest('.timeline-editor-action');
4818
+ if (actionEl) {
4819
+ var _props$onClickActionO;
4820
+ // @ts-expect-error 类型断言
4821
+ (_props$onClickActionO = props.onClickActionOnly) === null || _props$onClickActionO === void 0 ? void 0 : _props$onClickActionO.call(props, e, {
4822
+ action: {
4823
+ id: actionEl.dataset.actionId
4824
+ }
4825
+ });
4826
+ return;
4827
+ }
4801
4828
  engineRef.current.trigger('mousedown', {
4802
4829
  target: target,
4803
4830
  evt: e
@@ -4813,7 +4840,7 @@ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__d
4813
4840
  return function () {
4814
4841
  document.removeEventListener('mousedown', handleClickOutside);
4815
4842
  };
4816
- }, []);
4843
+ }, [props.onClickActionOnly]);
4817
4844
  // ref 数据
4818
4845
  React.useImperativeHandle(ref, function () {
4819
4846
  return {
@@ -4937,6 +4964,9 @@ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__d
4937
4964
  handleScroll.cancel();
4938
4965
  };
4939
4966
  }, [startLeft, scale, scaleWidth]);
4967
+ var _totalHeight = editorData.reduce(function (prev, cur) {
4968
+ return prev + (cur.rowHeight + 2 || 32);
4969
+ }, 0) + 32 + 24;
4940
4970
  return /*#__PURE__*/React__default['default'].createElement("div", {
4941
4971
  ref: domRef,
4942
4972
  style: style,
@@ -4990,7 +5020,7 @@ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__d
4990
5020
  id: "time-editor-container",
4991
5021
  ref: containerRef,
4992
5022
  style: {
4993
- height: '100%',
5023
+ height: _totalHeight,
4994
5024
  background: '#fff'
4995
5025
  },
4996
5026
  onClick: throttledOnClickTimeline
@@ -5036,7 +5066,7 @@ var Timeline = /*#__PURE__*/React__default['default'].memo(/*#__PURE__*/React__d
5036
5066
  setCursor: handleSetCursor,
5037
5067
  deltaScrollLeft: autoScroll && handleDeltaScrollLeft,
5038
5068
  allowCreateTrack: allowCreateTrack,
5039
- minHeight: index === 0 ? 122 : _totalHeight,
5069
+ minHeight: index === 0 ? 122 : undefined,
5040
5070
  containerRef: containerRef,
5041
5071
  onMutiSelectChange: props === null || props === void 0 ? void 0 : props.onMutiSelectChange,
5042
5072
  engineRef: engineRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sense-react-timeline-editor",
3
- "version": "1.1.32",
3
+ "version": "1.1.34",
4
4
  "author": "xzdarcy",
5
5
  "license": "MIT",
6
6
  "keywords": [