11import { AbstractEditor } from '../editor.js'
2- import { extend , each , trigger } from '../utilities.js'
2+ import { extend , trigger } from '../utilities.js'
33
44export class ArrayEditor extends AbstractEditor {
55 askConfirmation ( ) {
@@ -292,7 +292,7 @@ export class ArrayEditor extends AbstractEditor {
292292 empty ( hard ) {
293293 if ( ! this . rows ) return
294294 const self = this
295- each ( this . rows , ( i , row ) => {
295+ this . rows . forEach ( ( row , i ) => {
296296 if ( hard ) {
297297 if ( row . tab && row . tab . parentNode ) row . tab . parentNode . removeChild ( row . tab )
298298 self . destroyRow ( row , true )
@@ -326,7 +326,7 @@ export class ArrayEditor extends AbstractEditor {
326326
327327 refreshTabs ( refreshHeaders ) {
328328 const self = this
329- each ( this . rows , ( i , row ) => {
329+ this . rows . forEach ( row => {
330330 if ( ! row . tab ) return
331331
332332 if ( refreshHeaders ) {
@@ -356,7 +356,7 @@ export class ArrayEditor extends AbstractEditor {
356356 }
357357
358358 const self = this
359- each ( value , ( i , val ) => {
359+ value . forEach ( ( val , i ) => {
360360 if ( self . rows [ i ] ) {
361361 /* TODO: don't set the row's value if it hasn't changed */
362362 self . rows [ i ] . setValue ( val , initial )
@@ -380,13 +380,8 @@ export class ArrayEditor extends AbstractEditor {
380380 self . rows = self . rows . slice ( 0 , value . length )
381381
382382 /* Set the active tab */
383- let newActiveTab = null
384- each ( self . rows , ( i , row ) => {
385- if ( row . tab === self . active_tab ) {
386- newActiveTab = row . tab
387- return false
388- }
389- } )
383+ const row = self . rows . find ( row => row . tab === self . active_tab )
384+ let newActiveTab = typeof row !== 'undefined' ? row . tab : null
390385 if ( ! newActiveTab && self . rows . length ) newActiveTab = self . rows [ 0 ] . tab
391386
392387 self . active_tab = newActiveTab
@@ -403,18 +398,14 @@ export class ArrayEditor extends AbstractEditor {
403398 refreshValue ( force ) {
404399 const self = this
405400 const oldi = this . value ? this . value . length : 0
406- this . value = [ ]
407-
408- each ( this . rows , ( i , editor ) => {
409- /* Get the value for this editor */
410- self . value [ i ] = editor . getValue ( )
411- } )
401+ /* Get the value for this editor */
402+ this . value = this . rows . map ( editor => editor . getValue ( ) )
412403
413404 if ( oldi !== this . value . length || force ) {
414405 /* If we currently have minItems items in the array */
415406 const minItems = this . schema . minItems && this . schema . minItems >= this . rows . length
416407
417- each ( this . rows , ( i , editor ) => {
408+ this . rows . forEach ( ( editor , i ) => {
418409 /* Hide the move down button for the last row */
419410 if ( editor . movedown_button ) {
420411 if ( i === self . rows . length - 1 ) {
@@ -525,16 +516,9 @@ export class ArrayEditor extends AbstractEditor {
525516 }
526517
527518 const i = this . getAttribute ( 'data-i' ) * 1
528- const value = self . getValue ( )
529- const newval = [ ]
519+ const newval = self . getValue ( ) . filter ( ( row , j ) => j !== i )
530520 let newActiveTab = null
531521
532- each ( value , ( j , row ) => {
533- if ( j !== i ) {
534- newval . push ( row )
535- }
536- } )
537-
538522 const editor = self . rows [ i ]
539523
540524 self . setValue ( newval )
@@ -570,7 +554,7 @@ export class ArrayEditor extends AbstractEditor {
570554 e . stopPropagation ( )
571555 const i = this . getAttribute ( 'data-i' ) * 1
572556
573- each ( value , ( j , row ) => {
557+ value . forEach ( ( row , j ) => {
574558 if ( j === i ) {
575559 value . push ( row )
576560 }
@@ -784,7 +768,7 @@ export class ArrayEditor extends AbstractEditor {
784768 /* Get all the errors that pertain to this editor */
785769 const myErrors = [ ]
786770 const otherErrors = [ ]
787- each ( errors , ( i , error ) => {
771+ errors . forEach ( error => {
788772 if ( error . path === self . path ) {
789773 myErrors . push ( error )
790774 } else {
@@ -797,7 +781,7 @@ export class ArrayEditor extends AbstractEditor {
797781 if ( myErrors . length ) {
798782 this . error_holder . innerHTML = ''
799783 this . error_holder . style . display = ''
800- each ( myErrors , ( i , error ) => {
784+ myErrors . forEach ( error => {
801785 self . error_holder . appendChild ( self . theme . getErrorMessage ( error . message ) )
802786 } )
803787 /* Hide error area */
@@ -807,8 +791,8 @@ export class ArrayEditor extends AbstractEditor {
807791 }
808792
809793 /* Show errors for child editors */
810- each ( this . rows , ( i , row ) => {
794+ this . rows . forEach ( row =>
811795 row . showValidationErrors ( otherErrors )
812- } )
796+ )
813797 }
814798}
0 commit comments