| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.dm.MetaList = function VeDmMetaList( doc ) { |
| 17 |
|
| 18 |
OO.EventEmitter.call( this ); |
| 19 |
|
| 20 |
this.doc = doc; |
| 21 |
|
| 22 |
|
| 23 |
this.items = []; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
this.doc.connect( this, { |
| 28 |
nodeAttached: 'onNodeAttached', |
| 29 |
nodeDetached: 'onNodeDetached' |
| 30 |
} ); |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
OO.mixinClass( ve.dm.MetaList, OO.EventEmitter ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
ve.dm.MetaList.prototype.onNodeAttached = function ( node ) { |
| 57 |
const offsetPath = node.getOffsetPath(); |
| 58 |
if ( node instanceof ve.dm.MetaItem ) { |
| 59 |
const i = OO.binarySearch( this.items, ( other ) => ve.compareTuples( offsetPath, other.getOffsetPath() ), true ); |
| 60 |
this.items.splice( i, 0, node ); |
| 61 |
this.emit( 'insert', node ); |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
ve.dm.MetaList.prototype.onNodeDetached = function ( node ) { |
| 71 |
if ( node instanceof ve.dm.MetaItem ) { |
| 72 |
const i = this.items.indexOf( node ); |
| 73 |
if ( i !== -1 ) { |
| 74 |
this.items.splice( i, 1 ); |
| 75 |
this.emit( 'remove', node ); |
| 76 |
} |
| 77 |
} |
| 78 |
}; |
| 79 |
|
| 80 |
ve.dm.MetaList.prototype.indexOf = function ( item, group ) { |
| 81 |
const items = group ? this.getItemsInGroup( group ) : this.items; |
| 82 |
return items.indexOf( item ); |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
ve.dm.MetaList.prototype.getItemsInGroup = function ( group ) { |
| 95 |
return this.items.filter( ( item ) => item.getGroup() === group ); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
ve.dm.MetaList.prototype.getItems = function () { |
| 107 |
return this.items.slice(); |
| 108 |
}; |