@@ -19,6 +19,7 @@ var _lodash = require("lodash");
1919var _ListItemInlineEditControls = _interopRequireDefault ( require ( "./ListItemInlineEditControls" ) ) ;
2020var peaksActions = _interopRequireWildcard ( require ( "../actions/peaks-instance" ) ) ;
2121var _WaveformDataUtils = _interopRequireDefault ( require ( "../services/WaveformDataUtils" ) ) ;
22+ var _smeHooks = require ( "../services/sme-hooks" ) ;
2223function _getRequireWildcardCache ( e ) { if ( "function" != typeof WeakMap ) return null ; var r = new WeakMap ( ) , t = new WeakMap ( ) ; return ( _getRequireWildcardCache = function _getRequireWildcardCache ( e ) { return e ? t : r ; } ) ( e ) ; }
2324function _interopRequireWildcard ( e , r ) { if ( ! r && e && e . __esModule ) return e ; if ( null === e || "object" != _typeof ( e ) && "function" != typeof e ) return { "default" : e } ; var t = _getRequireWildcardCache ( r ) ; if ( t && t . has ( e ) ) return t . get ( e ) ; var n = { __proto__ : null } , a = Object . defineProperty && Object . getOwnPropertyDescriptor ; for ( var u in e ) if ( "default" !== u && { } . hasOwnProperty . call ( e , u ) ) { var i = a ? Object . getOwnPropertyDescriptor ( e , u ) : null ; i && ( i . get || i . set ) ? Object . defineProperty ( n , u , i ) : n [ u ] = e [ u ] ; } return n [ "default" ] = e , t && t . set ( e , n ) , n ; }
2425var structuralMetadataUtils = new _StructuralMetadataUtils [ "default" ] ( ) ;
@@ -44,14 +45,15 @@ function TimespanInlineForm(_ref) {
4445 var peaksInstance = ( 0 , _reactRedux . useSelector ) ( function ( state ) {
4546 return state . peaksInstance ;
4647 } ) ;
47- var isDragging = peaksInstance . isDragging ,
48+ var duration = peaksInstance . duration ,
49+ isDragging = peaksInstance . isDragging ,
4850 segment = peaksInstance . segment ,
4951 startTimeChanged = peaksInstance . startTimeChanged ;
5052
5153 // Dispatch actions
5254 var dispatch = ( 0 , _reactRedux . useDispatch ) ( ) ;
53- var activateSegment = function activateSegment ( id ) {
54- return dispatch ( peaksActions . activateSegment ( id ) ) ;
55+ var activateSegment = function activateSegment ( id , neighbors ) {
56+ return dispatch ( peaksActions . activateSegment ( id , neighbors ) ) ;
5557 } ;
5658 var insertPlaceholderSegment = function insertPlaceholderSegment ( item , wrapperSpans ) {
5759 return dispatch ( peaksActions . insertPlaceholderSegment ( item , wrapperSpans ) ) ;
@@ -86,6 +88,29 @@ function TimespanInlineForm(_ref) {
8688 setClonedSegment = _useState8 [ 1 ] ;
8789 var tempSmDataRef = ( 0 , _react . useRef ) ( ) ;
8890 var allSpansRef = ( 0 , _react . useRef ) ( [ ] ) ;
91+
92+ // Find neighboring timespans of the currently editing timespan
93+ var _useFindNeighborTimes = ( 0 , _smeHooks . useFindNeighborTimespans ) ( {
94+ item : item
95+ } ) ,
96+ prevSiblingRef = _useFindNeighborTimes . prevSiblingRef ,
97+ nextSiblingRef = _useFindNeighborTimes . nextSiblingRef ,
98+ parentTimespanRef = _useFindNeighborTimes . parentTimespanRef ;
99+
100+ // Validate timespan form when editing
101+ var _useTimespanFormValid = ( 0 , _smeHooks . useTimespanFormValidation ) ( {
102+ beginTime : beginTime ,
103+ endTime : endTime ,
104+ neighbors : {
105+ prevSiblingRef : prevSiblingRef ,
106+ nextSiblingRef : nextSiblingRef ,
107+ parentTimespanRef : parentTimespanRef
108+ } ,
109+ timespanTitle : timespanTitle
110+ } ) ,
111+ formIsValid = _useTimespanFormValid . formIsValid ,
112+ isBeginValid = _useTimespanFormValid . isBeginValid ,
113+ isEndValid = _useTimespanFormValid . isEndValid ;
89114 ( 0 , _react . useEffect ) ( function ( ) {
90115 // Get a fresh copy of store data
91116 tempSmDataRef . current = ( 0 , _lodash . cloneDeep ) ( smData ) ;
@@ -99,7 +124,11 @@ function TimespanInlineForm(_ref) {
99124 setEndTime ( formValues . endTime ) ;
100125 setTimespanTitle ( formValues . timespanTitle ) ;
101126 setClonedSegment ( formValues . clonedSegment ) ;
102- activateSegment ( item . id ) ;
127+ activateSegment ( item . id , {
128+ previousSibling : prevSiblingRef . current ,
129+ nextSibling : nextSiblingRef . current ,
130+ parentTimespan : parentTimespanRef . current
131+ } ) ;
103132 } else {
104133 handleInvalidTimespan ( ) ;
105134 }
@@ -108,7 +137,7 @@ function TimespanInlineForm(_ref) {
108137 tempSmDataRef . current = structuralMetadataUtils . deleteListItem ( item . id , tempSmDataRef . current ) ;
109138
110139 // Save a reference to all the spans for future calculations
111- allSpansRef . current = structuralMetadataUtils . getItemsOfType ( 'span' , tempSmDataRef . current ) ;
140+ allSpansRef . current = structuralMetadataUtils . getItemsOfType ( [ 'span' ] , tempSmDataRef . current ) ;
112141
113142 // Get segment from current peaks instance
114143 var currentSegment = peaksInstance . peaks . segments . getSegment ( item . id ) ;
@@ -127,7 +156,11 @@ function TimespanInlineForm(_ref) {
127156 // When handles in waveform are dragged clear out isInitializing and isTyping flags
128157 if ( isInitializing ) setIsInitializing ( 0 ) ;
129158 if ( isTyping ) setIsTyping ( 0 ) ;
130- var _waveformUtils$valida = waveformUtils . validateSegment ( segment , startTimeChanged , peaksInstance . peaks , peaksInstance . duration ) ,
159+ var _waveformUtils$valida = waveformUtils . validateSegment ( segment , startTimeChanged , duration , {
160+ previousSibling : prevSiblingRef . current ,
161+ nextSibling : nextSiblingRef . current ,
162+ parentTimespan : parentTimespanRef . current
163+ } ) ,
131164 _startTime = _waveformUtils$valida . startTime ,
132165 _endTime2 = _waveformUtils$valida . endTime ;
133166 setBeginTime ( structuralMetadataUtils . toHHmmss ( _startTime ) ) ;
@@ -141,10 +174,10 @@ function TimespanInlineForm(_ref) {
141174 * they cannot be added at the time Peaks is initialized.
142175 */
143176 var handleInvalidTimespan = function handleInvalidTimespan ( ) {
144- var itemIndex = structuralMetadataUtils . getItemsOfType ( 'span' , smData ) . findIndex ( function ( i ) {
177+ var itemIndex = structuralMetadataUtils . getItemsOfType ( [ 'span' ] , smData ) . findIndex ( function ( i ) {
145178 return i . id === item . id ;
146179 } ) ;
147- var allSpans = structuralMetadataUtils . getItemsOfType ( 'span' , tempSmDataRef . current ) ;
180+ var allSpans = structuralMetadataUtils . getItemsOfType ( [ 'span' ] , tempSmDataRef . current ) ;
148181 var wrapperSpans = {
149182 prevSpan : null ,
150183 nextSpan : null
@@ -159,11 +192,6 @@ function TimespanInlineForm(_ref) {
159192 setEndTime ( structuralMetadataUtils . toHHmmss ( placeholderSegment . endTime ) ) ;
160193 setTimespanTitle ( placeholderSegment . labelText ) ;
161194 } ;
162- var formIsValid = function formIsValid ( ) {
163- var titleValid = ( 0 , _formHelper . isTitleValid ) ( timespanTitle ) ;
164- var timesValidResponse = ( 0 , _formHelper . validTimespans ) ( beginTime , endTime , peaksInstance . duration , allSpansRef . current ) ;
165- return titleValid && timesValidResponse . valid ;
166- } ;
167195 var handleCancelClick = function handleCancelClick ( ) {
168196 // Revert to segment to the state prior to editing
169197 revertSegment ( clonedSegment ) ;
@@ -226,8 +254,8 @@ function TimespanInlineForm(_ref) {
226254 type : "text" ,
227255 style : styles . formControl ,
228256 value : timespanTitle ,
229- isValid : ( 0 , _formHelper . getValidationTitleState ) ( timespanTitle ) ,
230- isInvalid : ! ( 0 , _formHelper . getValidationTitleState ) ( timespanTitle ) ,
257+ isValid : ( 0 , _formHelper . isTitleValid ) ( timespanTitle ) ,
258+ isInvalid : ! ( 0 , _formHelper . isTitleValid ) ( timespanTitle ) ,
231259 onChange : handleInputChange ,
232260 "data-testid" : "timespan-inline-form-title" ,
233261 className : "mx-0"
@@ -248,8 +276,8 @@ function TimespanInlineForm(_ref) {
248276 style : styles . formControl ,
249277 value : beginTime ,
250278 onChange : handleInputChange ,
251- isValid : ( 0 , _formHelper . getValidationBeginState ) ( beginTime , allSpansRef . current ) ,
252- isInvalid : ! ( 0 , _formHelper . getValidationBeginState ) ( beginTime , allSpansRef . current ) ,
279+ isValid : isBeginValid ,
280+ isInvalid : ! isBeginValid ,
253281 "data-testid" : "timespan-inline-form-begintime" ,
254282 className : "mx-0"
255283 } ) ) ) , /*#__PURE__*/ _react [ "default" ] . createElement ( _Form [ "default" ] . Group , {
@@ -268,13 +296,13 @@ function TimespanInlineForm(_ref) {
268296 type : "text" ,
269297 style : styles . formControl ,
270298 value : endTime ,
271- isValid : ( 0 , _formHelper . getValidationEndState ) ( beginTime , endTime , allSpansRef . current , peaksInstance . duration ) ,
272- isInvalid : ! ( 0 , _formHelper . getValidationEndState ) ( beginTime , endTime , allSpansRef . current , peaksInstance . duration ) ,
299+ isValid : isEndValid ,
300+ isInvalid : ! isEndValid ,
273301 onChange : handleInputChange ,
274302 "data-testid" : "timespan-inline-form-endtime" ,
275303 className : "mx-0"
276304 } ) ) ) ) , /*#__PURE__*/ _react [ "default" ] . createElement ( _ListItemInlineEditControls [ "default" ] , {
277- formIsValid : formIsValid ( ) ,
305+ formIsValid : formIsValid ,
278306 handleSaveClick : handleSaveClick ,
279307 handleCancelClick : handleCancelClick
280308 } ) ) ;
0 commit comments