| 1 |
import IMask from './holder.js'; |
| 2 |
|
| 3 |
/** Provides details of changing model value */ |
| 4 |
class ChangeDetails { |
| 5 |
/** Inserted symbols */ |
| 6 |
|
| 7 |
/** Additional offset if any changes occurred before tail */ |
| 8 |
|
| 9 |
/** Raw inserted is used by dynamic mask */ |
| 10 |
|
| 11 |
/** Can skip chars */ |
| 12 |
|
| 13 |
static normalize(prep) { |
| 14 |
return Array.isArray(prep) ? prep : [prep, new ChangeDetails()]; |
| 15 |
} |
| 16 |
constructor(details) { |
| 17 |
Object.assign(this, { |
| 18 |
inserted: '', |
| 19 |
rawInserted: '', |
| 20 |
tailShift: 0, |
| 21 |
skip: false |
| 22 |
}, details); |
| 23 |
} |
| 24 |
|
| 25 |
/** Aggregate changes */ |
| 26 |
aggregate(details) { |
| 27 |
this.inserted += details.inserted; |
| 28 |
this.rawInserted += details.rawInserted; |
| 29 |
this.tailShift += details.tailShift; |
| 30 |
this.skip = this.skip || details.skip; |
| 31 |
return this; |
| 32 |
} |
| 33 |
|
| 34 |
/** Total offset considering all changes */ |
| 35 |
get offset() { |
| 36 |
return this.tailShift + this.inserted.length; |
| 37 |
} |
| 38 |
get consumed() { |
| 39 |
return Boolean(this.rawInserted) || this.skip; |
| 40 |
} |
| 41 |
equals(details) { |
| 42 |
return this.inserted === details.inserted && this.tailShift === details.tailShift && this.rawInserted === details.rawInserted && this.skip === details.skip; |
| 43 |
} |
| 44 |
} |
| 45 |
IMask.ChangeDetails = ChangeDetails; |
| 46 |
|
| 47 |
export { ChangeDetails as default }; |
| 48 |
|