@blocksuite/virgo
Advanced tools
Comparing version 0.4.0-20230201062929-3667cc0 to 0.4.0-20230201063624-4e0463b
@@ -77,3 +77,4 @@ import type * as Y from 'yjs'; | ||
private _onUpdateVRange; | ||
private _transact; | ||
} | ||
//# sourceMappingURL=virgo.d.ts.map |
@@ -149,3 +149,5 @@ import { ZERO_WIDTH_SPACE } from './constant.js'; | ||
deleteText(vRange) { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
}); | ||
} | ||
@@ -155,15 +157,19 @@ // TODO add support for formatting | ||
const currentDelta = this.getDeltaByRangeIndex(vRange.index); | ||
this.yText.delete(vRange.index, vRange.length); | ||
if (vRange.index > 0 && | ||
currentDelta && | ||
currentDelta.attributes.type !== 'line-break') { | ||
this.yText.insert(vRange.index, text, currentDelta.attributes); | ||
} | ||
else { | ||
this.yText.insert(vRange.index, text, { type: 'base' }); | ||
} | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
if (vRange.index > 0 && | ||
currentDelta && | ||
currentDelta.attributes.type !== 'line-break') { | ||
this.yText.insert(vRange.index, text, currentDelta.attributes); | ||
} | ||
else { | ||
this.yText.insert(vRange.index, text, { type: 'base' }); | ||
} | ||
}); | ||
} | ||
insertLineBreak(vRange) { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this.yText.insert(vRange.index, '\n', { type: 'line-break' }); | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this.yText.insert(vRange.index, '\n', { type: 'line-break' }); | ||
}); | ||
} | ||
@@ -185,3 +191,5 @@ formatText(vRange, attributes, options = {}) { | ||
} | ||
this.yText.format(targetVRange.index, targetVRange.length, attributes); | ||
this._transact(() => { | ||
this.yText.format(targetVRange.index, targetVRange.length, attributes); | ||
}); | ||
} | ||
@@ -199,5 +207,7 @@ } | ||
const unset = Object.fromEntries(coverDeltas.flatMap(delta => Object.keys(delta.attributes).map(key => [key, null]))); | ||
this.yText.format(vRange.index, vRange.length, { | ||
...unset, | ||
type: 'base', | ||
this._transact(() => { | ||
this.yText.format(vRange.index, vRange.length, { | ||
...unset, | ||
type: 'base', | ||
}); | ||
}); | ||
@@ -446,2 +456,9 @@ } | ||
} | ||
_transact(fn) { | ||
const doc = this.yText.doc; | ||
if (!doc) { | ||
throw new Error('yText is not attached to a doc'); | ||
} | ||
doc.transact(fn, doc.clientID); | ||
} | ||
} | ||
@@ -448,0 +465,0 @@ function textPointToDomPoint(text, offset, rootElement) { |
{ | ||
"name": "@blocksuite/virgo", | ||
"version": "0.4.0-20230201062929-3667cc0", | ||
"version": "0.4.0-20230201063624-4e0463b", | ||
"description": "A micro editor.", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@blocksuite/global": "0.4.0-20230201062929-3667cc0" | ||
"@blocksuite/global": "0.4.0-20230201063624-4e0463b" | ||
}, | ||
@@ -29,0 +29,0 @@ "scripts": { |
@@ -161,3 +161,5 @@ import type * as Y from 'yjs'; | ||
deleteText(vRange: VRange): void { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
}); | ||
} | ||
@@ -168,18 +170,22 @@ | ||
const currentDelta = this.getDeltaByRangeIndex(vRange.index); | ||
this.yText.delete(vRange.index, vRange.length); | ||
if ( | ||
vRange.index > 0 && | ||
currentDelta && | ||
currentDelta.attributes.type !== 'line-break' | ||
) { | ||
this.yText.insert(vRange.index, text, currentDelta.attributes); | ||
} else { | ||
this.yText.insert(vRange.index, text, { type: 'base' }); | ||
} | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
if ( | ||
vRange.index > 0 && | ||
currentDelta && | ||
currentDelta.attributes.type !== 'line-break' | ||
) { | ||
this.yText.insert(vRange.index, text, currentDelta.attributes); | ||
} else { | ||
this.yText.insert(vRange.index, text, { type: 'base' }); | ||
} | ||
}); | ||
} | ||
insertLineBreak(vRange: VRange): void { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this.yText.insert(vRange.index, '\n', { type: 'line-break' }); | ||
this._transact(() => { | ||
this.yText.delete(vRange.index, vRange.length); | ||
this.yText.insert(vRange.index, '\n', { type: 'line-break' }); | ||
}); | ||
} | ||
@@ -217,3 +223,9 @@ | ||
this.yText.format(targetVRange.index, targetVRange.length, attributes); | ||
this._transact(() => { | ||
this.yText.format( | ||
targetVRange.index, | ||
targetVRange.length, | ||
attributes | ||
); | ||
}); | ||
} | ||
@@ -238,5 +250,7 @@ } | ||
this.yText.format(vRange.index, vRange.length, { | ||
...unset, | ||
type: 'base', | ||
this._transact(() => { | ||
this.yText.format(vRange.index, vRange.length, { | ||
...unset, | ||
type: 'base', | ||
}); | ||
}); | ||
@@ -613,2 +627,11 @@ } | ||
}; | ||
private _transact(fn: () => void): void { | ||
const doc = this.yText.doc; | ||
if (!doc) { | ||
throw new Error('yText is not attached to a doc'); | ||
} | ||
doc.transact(fn, doc.clientID); | ||
} | ||
} | ||
@@ -615,0 +638,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
168759
1975
+ Added@blocksuite/global@0.4.0-20230201063624-4e0463b(transitive)
- Removed@blocksuite/global@0.4.0-20230201062929-3667cc0(transitive)