* Apply a Delta on this shared type. * * @param {delta.DeltaAny} d The changes to apply on this element. * @param {AbstractAttributionManager} am * * @public
(d, am = noAttributionsManager)
| 1029 | * @public |
| 1030 | */ |
| 1031 | applyDelta (d, am = noAttributionsManager) { |
| 1032 | if (this.doc == null) { |
| 1033 | (this._prelim || (this._prelim = /** @type {any} */ (delta.create()))).apply(d) |
| 1034 | } else { |
| 1035 | // @todo this was moved here from ytext. Make this more generic |
| 1036 | transact(this.doc, transaction => { |
| 1037 | const currPos = new ItemTextListPosition(null, this._start, 0, new Map(), am) |
| 1038 | for (const op of d.children) { |
| 1039 | if (delta.$textOp.check(op)) { |
| 1040 | insertContent(transaction, /** @type {any} */ (this), currPos, new ContentString(op.insert), op.format || {}) |
| 1041 | } else if (delta.$insertOp.check(op)) { |
| 1042 | insertContentHelper(transaction, this, currPos, op.insert, op.format || {}) |
| 1043 | } else if (delta.$retainOp.check(op)) { |
| 1044 | currPos.formatText(transaction, /** @type {any} */ (this), op.retain, op.format || {}) |
| 1045 | } else if (delta.$deleteOp.check(op)) { |
| 1046 | deleteText(transaction, currPos, op.delete) |
| 1047 | } else if (delta.$modifyOp.check(op)) { |
| 1048 | if (currPos.right) { |
| 1049 | /** @type {ContentType} */ (currPos.right.content).type.applyDelta(op.value) |
| 1050 | } else { |
| 1051 | error.unexpectedCase() |
| 1052 | } |
| 1053 | currPos.formatText(transaction, /** @type {any} */ (this), 1, op.format || {}) |
| 1054 | } else { |
| 1055 | error.unexpectedCase() |
| 1056 | } |
| 1057 | } |
| 1058 | for (const op of d.attrs) { |
| 1059 | if (delta.$setAttrOp.check(op)) { |
| 1060 | typeMapSet(transaction, /** @type {any} */ (this), /** @type {any} */ (op.key), op.value) |
| 1061 | } else if (delta.$deleteAttrOp.check(op)) { |
| 1062 | typeMapDelete(transaction, /** @type {any} */ (this), /** @type {any} */ (op.key)) |
| 1063 | } else { |
| 1064 | const sub = typeMapGet(/** @type {any} */ (this), /** @type {any} */ (op.key)) |
| 1065 | if (!(sub instanceof YType)) { |
| 1066 | error.unexpectedCase() |
| 1067 | } |
| 1068 | sub.applyDelta(op.value) |
| 1069 | } |
| 1070 | } |
| 1071 | }) |
| 1072 | } |
| 1073 | return this |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * Makes a copy of this data type that can be included somewhere else. |
no test coverage detected