MCPcopy
hub / github.com/yjs/yjs / applyDelta

Method applyDelta

src/ytype.js:1031–1074  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 15

fromMethod · 0.95
_integrateMethod · 0.95
clearAttrsMethod · 0.95
deleteAttrMethod · 0.95
setAttrMethod · 0.95
insertMethod · 0.95
formatMethod · 0.95
deleteMethod · 0.95
cloneMethod · 0.80
testBasicsFunction · 0.80
testAttributionsFunction · 0.80
testAttributedEventsFunction · 0.80

Calls 8

formatTextMethod · 0.95
transactFunction · 0.90
insertContentFunction · 0.85
insertContentHelperFunction · 0.85
deleteTextFunction · 0.85
typeMapSetFunction · 0.85
typeMapDeleteFunction · 0.85
typeMapGetFunction · 0.85

Tested by

no test coverage detected