@@ -53,13 +53,6 @@ export class Stepper extends StepState {
5353 if ( serializedState !== null ) {
5454 this . _log . debug ( 'STEPSTATE:loading serialized state' )
5555 this . loadFromJSON ( serializedState )
56- } else {
57- // Initialize the state machine with SOS and EOS nodes
58- if ( this . depth === 0 ) {
59- this . push ( 'SOS' )
60- this . push ( 'EOS' )
61- this . _currentIndex = 1 // start at EOS or whatever is first
62- }
6356 }
6457
6558 return new StepperProxy ( this )
@@ -144,19 +137,9 @@ export class Stepper extends StepState {
144137 try {
145138 // Create a new state with auto-incremented id
146139 if ( item . path !== undefined ) {
147- // If at level 0, insert before EOS state
148- if ( this . depth === 0 ) {
149- state = this . insert ( item . path , - 2 , item )
150- } else {
151- state = this . push ( item . path , item )
152- }
140+ state = this . push ( item . path , item )
153141 } else {
154- // If at level 0, insert before EOS state
155- if ( this . depth === 0 ) {
156- state = this . insert ( null , - 2 , item )
157- } else {
158- state = this . push ( null , item )
159- }
142+ state = this . push ( null , item )
160143 }
161144 } catch ( error ) {
162145 this . _log . error ( error . message )
@@ -176,8 +159,7 @@ export class Stepper extends StepState {
176159 const itemsToAdd = Array . isArray ( items ) ? items : [ items ]
177160
178161 // Check if adding these items would exceed maxStepperRows
179- // Subtract 2 to account for SOS and EOS states
180- if ( this . _states . length - 2 + itemsToAdd . length > config . maxStepperRows ) {
162+ if ( this . _states . length + itemsToAdd . length > config . maxStepperRows ) {
181163 this . _log . error (
182164 `Cannot append ${ itemsToAdd . length } rows as it exceeds the safety limit of ${ config . maxStepperRows } `
183165 )
@@ -402,32 +384,14 @@ export class Stepper extends StepState {
402384 rng = Math . random
403385 }
404386
405- // Fisher-Yates shuffle algorithm
406- if ( this . depth === 0 ) {
407- // At depth 0, we need to preserve SOS and EOS states
408- // Only shuffle the middle elements (excluding first and last)
409- const start = 1 // Skip SOS
410- const end = this . _states . length - 1 // Skip EOS
411-
412- for ( let i = end - 1 ; i > start ; i -- ) {
413- // j can be between start and i (excluding SOS and EOS)
414- const j = start + Math . floor ( rng ( ) * ( i - start + 1 ) )
415- ; [ this . _states [ i ] , this . _states [ j ] ] = [ this . _states [ j ] , this . _states [ i ] ]
416-
417- // Update indices for the swapped elements
418- this . _states [ i ] . _currentIndex = i - 1 // -1 because we skip SOS
419- this . _states [ j ] . _currentIndex = j - 1 // -1 because we skip SOS
420- }
421- } else {
422- // For other depths, shuffle all elements
423- for ( let i = this . _states . length - 1 ; i > 0 ; i -- ) {
424- const j = Math . floor ( rng ( ) * ( i + 1 ) )
425- ; [ this . _states [ i ] , this . _states [ j ] ] = [ this . _states [ j ] , this . _states [ i ] ]
426-
427- // Update indices for the swapped elements
428- this . _states [ i ] . _currentIndex = i
429- this . _states [ j ] . _currentIndex = j
430- }
387+ // For other depths, shuffle all elements
388+ for ( let i = this . _states . length - 1 ; i > 0 ; i -- ) {
389+ const j = Math . floor ( rng ( ) * ( i + 1 ) )
390+ ; [ this . _states [ i ] , this . _states [ j ] ] = [ this . _states [ j ] , this . _states [ i ] ]
391+
392+ // Update indices for the swapped elements
393+ this . _states [ i ] . _currentIndex = i
394+ this . _states [ j ] . _currentIndex = j
431395 }
432396
433397 // Mark as shuffled
@@ -447,11 +411,6 @@ export class Stepper extends StepState {
447411 */
448412 forEach ( callback ) {
449413 this . _states . forEach ( ( item , index ) => {
450- // Skip SOS and EOS states when at depth 0
451- if ( this . depth === 0 && ( index === 0 || index === this . states . length - 1 ) ) {
452- return
453- }
454-
455414 // Call the callback and check if it returns a new value
456415 const result = callback ( item , index )
457416 if ( result !== undefined ) {
@@ -585,12 +544,6 @@ export class Stepper extends StepState {
585544 */
586545 clearSubTree ( ) {
587546 super . clearSubTree ( )
588- // Initialize the state machine with SOS and EOS nodes
589- if ( this . depth === 0 ) {
590- this . push ( 'SOS' )
591- this . push ( 'EOS' )
592- this . _currentIndex = 1 // start at EOS or whatever is first
593- }
594547
595548 this . _shuffled = false
596549 }
0 commit comments