@manuscripts/track-changes-plugin 0.0.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -45
- package/dist/actions.d.ts +8 -1
- package/dist/index.cjs +1591 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +25 -13
- package/dist/index.js +173 -144
- package/dist/plugin.d.ts +2 -2
- package/dist/track/deleteNode.d.ts +1 -1
- package/dist/track/mergeNode.d.ts +1 -1
- package/dist/track/node-utils.d.ts +4 -11
- package/dist/track/steps/deleteAndMergeSplitNodes.d.ts +1 -1
- package/dist/track/steps/setFragmentAsInserted.d.ts +1 -1
- package/dist/track/steps/track-utils.d.ts +0 -1
- package/dist/track/trackTransaction.d.ts +2 -2
- package/dist/types/change.d.ts +4 -1
- package/package.json +17 -21
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export { trackChangesPluginKey, trackChangesPlugin } from './plugin';
|
|
17
|
-
export
|
|
17
|
+
export { skipTracking } from './actions';
|
|
18
18
|
export * as trackCommands from './commands';
|
|
19
19
|
export { enableDebug } from './utils/logger';
|
|
20
20
|
export { ChangeSet } from './ChangeSet';
|
package/dist/index.es.js
CHANGED
|
@@ -327,8 +327,9 @@ function deleteNode(node, pos, tr) {
|
|
|
327
327
|
var _a;
|
|
328
328
|
const startPos = tr.doc.resolve(pos + 1);
|
|
329
329
|
const range = startPos.blockRange(tr.doc.resolve(startPos.pos - 2 + node.nodeSize));
|
|
330
|
-
const targetDepth = range
|
|
331
|
-
|
|
330
|
+
const targetDepth = range && liftTarget(range);
|
|
331
|
+
// Check with typeof since with old prosemirror-transform targetDepth is undefined
|
|
332
|
+
if (range && typeof targetDepth === 'number') {
|
|
332
333
|
return tr.lift(range, targetDepth);
|
|
333
334
|
}
|
|
334
335
|
const resPos = tr.doc.resolve(pos);
|
|
@@ -505,7 +506,7 @@ function applyAcceptedRejectedChanges(tr, schema, changes, deleteMap = new Mappi
|
|
|
505
506
|
// or were already deleted by an applied block delete
|
|
506
507
|
const { pos: from, deleted } = deleteMap.mapResult(change.from), node = tr.doc.nodeAt(from), noChangeNeeded = deleted || ChangeSet.shouldNotDelete(change);
|
|
507
508
|
if (!node) {
|
|
508
|
-
log.warn('no node found to update for change', change);
|
|
509
|
+
!deleted && log.warn('no node found to update for change', change);
|
|
509
510
|
return;
|
|
510
511
|
}
|
|
511
512
|
if (ChangeSet.isTextChange(change) && noChangeNeeded) {
|
|
@@ -929,6 +930,7 @@ function deleteAndMergeSplitNodes(from, to, gap, startDoc, newTr, schema, trackA
|
|
|
929
930
|
// But from what I remember what it safeguards against is, when you've already deleted a node
|
|
930
931
|
// say an inserted blockquote that had all its children deleted, nodesBetween still iterates over those
|
|
931
932
|
// nodes and therefore we have to make this check to ensure they still exist in the doc.
|
|
933
|
+
//
|
|
932
934
|
if (nodeEnd > offsetFrom && !nodeWasDeleted && !wasWithinGap) {
|
|
933
935
|
// |<p>asdf</p>| -> node deleted completely
|
|
934
936
|
const nodeCompletelyDeleted = offsetPos >= offsetFrom && nodeEnd <= offsetTo;
|
|
@@ -1209,11 +1211,9 @@ function trackReplaceStep(step, oldState, newTr, attrs) {
|
|
|
1209
1211
|
* This skips the direct dependency to prosemirror-state where multiple versions might cause conflicts
|
|
1210
1212
|
* as the created instances might belong to different prosemirror-state import than one used in the editor.
|
|
1211
1213
|
* @param sel
|
|
1212
|
-
* @param doc
|
|
1213
|
-
* @param from
|
|
1214
1214
|
* @returns
|
|
1215
1215
|
*/
|
|
1216
|
-
const
|
|
1216
|
+
const getSelectionStaticConstructor = (sel) => Object.getPrototypeOf(sel).constructor;
|
|
1217
1217
|
/**
|
|
1218
1218
|
* Inverts transactions to wrap their contents/operations with track data instead
|
|
1219
1219
|
*
|
|
@@ -1257,7 +1257,12 @@ function trackTransaction(tr, oldState, newTr, userID) {
|
|
|
1257
1257
|
else if (step instanceof ReplaceStep) {
|
|
1258
1258
|
const selectionPos = trackReplaceStep(step, oldState, newTr, emptyAttrs);
|
|
1259
1259
|
if (!wasNodeSelection) {
|
|
1260
|
-
|
|
1260
|
+
const sel = getSelectionStaticConstructor(tr.selection);
|
|
1261
|
+
// Use Selection.near to fix selections that point to a block node instead of inline content
|
|
1262
|
+
// eg when inserting a complete new paragraph. -1 finds the first valid position moving backwards
|
|
1263
|
+
// inside the content
|
|
1264
|
+
const near = sel.near(newTr.doc.resolve(selectionPos), -1);
|
|
1265
|
+
newTr.setSelection(near);
|
|
1261
1266
|
}
|
|
1262
1267
|
}
|
|
1263
1268
|
else if (step instanceof ReplaceAroundStep) {
|
|
@@ -1265,10 +1270,15 @@ function trackTransaction(tr, oldState, newTr, userID) {
|
|
|
1265
1270
|
// } else if (step instanceof AddMarkStep) {
|
|
1266
1271
|
// } else if (step instanceof RemoveMarkStep) {
|
|
1267
1272
|
}
|
|
1273
|
+
// TODO: here we could check whether adjacent inserts & deletes cancel each other out.
|
|
1274
|
+
// However, this should not be done by diffing and only matching node or char by char instead since
|
|
1275
|
+
// it's A easier and B more intuitive to user.
|
|
1268
1276
|
// The old meta keys are not copied to the new transaction since this will cause race-conditions
|
|
1269
|
-
// when a single meta-field is
|
|
1270
|
-
// inputType
|
|
1271
|
-
//
|
|
1277
|
+
// when a single meta-field is expected to having been processed / removed. Generic input meta keys,
|
|
1278
|
+
// inputType and uiEvent, are re-added since some plugins might depend on them and process the transaction
|
|
1279
|
+
// after track-changes plugin.
|
|
1280
|
+
tr.getMeta('inputType') && newTr.setMeta('inputType', tr.getMeta('inputType'));
|
|
1281
|
+
tr.getMeta('uiEvent') && newTr.setMeta('uiEvent', tr.getMeta('uiEvent'));
|
|
1272
1282
|
});
|
|
1273
1283
|
// This is kinda hacky solution at the moment to maintain NodeSelections over transactions
|
|
1274
1284
|
// These are required by at least cross-references that need it to activate the selector pop-up
|
|
@@ -1276,7 +1286,8 @@ function trackTransaction(tr, oldState, newTr, userID) {
|
|
|
1276
1286
|
const mappedPos = newTr.mapping.map(tr.selection.from);
|
|
1277
1287
|
const resPos = newTr.doc.resolve(mappedPos);
|
|
1278
1288
|
const nodePos = mappedPos - (((_a = resPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.nodeSize) || 0);
|
|
1279
|
-
|
|
1289
|
+
const sel = getSelectionStaticConstructor(tr.selection);
|
|
1290
|
+
newTr.setSelection(sel.create(newTr.doc, nodePos));
|
|
1280
1291
|
}
|
|
1281
1292
|
log.info('NEW transaction', newTr);
|
|
1282
1293
|
return newTr;
|
|
@@ -1326,7 +1337,8 @@ const trackChangesPlugin = (opts = { userID: 'anonymous:Anonymous' }) => {
|
|
|
1326
1337
|
key: trackChangesPluginKey,
|
|
1327
1338
|
props: {
|
|
1328
1339
|
editable(state) {
|
|
1329
|
-
|
|
1340
|
+
var _a;
|
|
1341
|
+
return ((_a = trackChangesPluginKey.getState(state)) === null || _a === void 0 ? void 0 : _a.status) !== TrackChangesStatus.viewSnapshots;
|
|
1330
1342
|
},
|
|
1331
1343
|
},
|
|
1332
1344
|
state: {
|
|
@@ -1396,7 +1408,6 @@ const trackChangesPlugin = (opts = { userID: 'anonymous:Anonymous' }) => {
|
|
|
1396
1408
|
(wasAppended && getAction(wasAppended, TrackChangesAction.skipTrack));
|
|
1397
1409
|
if (tr.docChanged && !skipMetaUsed && !skipTrackUsed && !tr.getMeta('history$')) {
|
|
1398
1410
|
createdTr = trackTransaction(tr, oldState, createdTr, userID);
|
|
1399
|
-
createdTr.setMeta('origin', trackChangesPluginKey);
|
|
1400
1411
|
infiniteLoopCounter.iters += 1;
|
|
1401
1412
|
}
|
|
1402
1413
|
docChanged = docChanged || tr.docChanged;
|
|
@@ -1423,6 +1434,7 @@ const trackChangesPlugin = (opts = { userID: 'anonymous:Anonymous' }) => {
|
|
|
1423
1434
|
log.warn('had to fix inconsistent changes in', createdTr);
|
|
1424
1435
|
}
|
|
1425
1436
|
if (docChanged || createdTr.docChanged || changed) {
|
|
1437
|
+
createdTr.setMeta('origin', trackChangesPluginKey);
|
|
1426
1438
|
return setAction(createdTr, TrackChangesAction.refreshChanges, true);
|
|
1427
1439
|
}
|
|
1428
1440
|
return null;
|