@dxos/react-ui-editor 0.3.11-main.85b2690 → 0.3.11-main.86514dd

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.
@@ -1214,6 +1214,60 @@ var highlightDecorations = EditorView5.decorations.compute([
1214
1214
  }).filter(nonNullable) ?? [];
1215
1215
  return Decoration3.set(decorations);
1216
1216
  });
1217
+ var trackPastedComments = (onMove) => {
1218
+ let tracked = null;
1219
+ const registerCopy = (event, view) => {
1220
+ const comments2 = view.state.field(commentsStateField);
1221
+ const { main } = view.state.selection;
1222
+ const inSel = comments2.ranges.filter((range) => range.from >= main.from && range.to <= main.to && range.from < range.to);
1223
+ if (!inSel.length) {
1224
+ tracked = null;
1225
+ } else {
1226
+ tracked = {
1227
+ text: view.state.doc.slice(main.from, main.to),
1228
+ comments: inSel.map((range) => ({
1229
+ from: range.from - main.from,
1230
+ to: range.to - main.from,
1231
+ id: range.id
1232
+ }))
1233
+ };
1234
+ }
1235
+ };
1236
+ return [
1237
+ EditorView5.domEventHandlers({
1238
+ cut: registerCopy,
1239
+ copy: registerCopy
1240
+ }),
1241
+ EditorView5.updateListener.of((update2) => {
1242
+ if (tracked) {
1243
+ const paste = update2.transactions.find((tr) => tr.isUserEvent("input.paste"));
1244
+ if (paste) {
1245
+ let found = -1;
1246
+ paste.changes.iterChanges((fromA, toA, fromB, toB, text) => {
1247
+ if (text.eq(tracked.text)) {
1248
+ for (let i = update2.transactions.indexOf(paste) + 1; i < update2.transactions.length; i++) {
1249
+ fromB = update2.transactions[i].changes.mapPos(fromB);
1250
+ }
1251
+ found = fromB;
1252
+ }
1253
+ });
1254
+ if (found > -1) {
1255
+ const active = update2.view.state.field(commentsStateField).ranges;
1256
+ for (const moved of tracked.comments) {
1257
+ if (active.some((range) => range.id === moved.id && range.from === range.to)) {
1258
+ onMove(moved.id, Cursor.getCursorFromRange(update2.view.state.facet(Cursor.converter), {
1259
+ from: found + moved.from,
1260
+ to: found + moved.to
1261
+ }));
1262
+ }
1263
+ }
1264
+ }
1265
+ tracked = null;
1266
+ }
1267
+ }
1268
+ })
1269
+ ];
1270
+ };
1217
1271
  var comments = (options = {}) => {
1218
1272
  const { key: shortcut = "meta-'" } = options;
1219
1273
  const handleSelect = debounce((state) => options.onSelect?.(state), 200);
@@ -1221,7 +1275,7 @@ var comments = (options = {}) => {
1221
1275
  const cursorConverter3 = view.state.facet(Cursor.converter);
1222
1276
  invariant2(options.onCreate, void 0, {
1223
1277
  F: __dxlog_file3,
1224
- L: 177,
1278
+ L: 240,
1225
1279
  S: void 0,
1226
1280
  A: [
1227
1281
  "options.onCreate",
@@ -1324,7 +1378,7 @@ var comments = (options = {}) => {
1324
1378
  thread: range.id
1325
1379
  }, {
1326
1380
  F: __dxlog_file3,
1327
- L: 274,
1381
+ L: 337,
1328
1382
  S: void 0,
1329
1383
  C: (f, a) => f(...a)
1330
1384
  });
@@ -1377,7 +1431,8 @@ var comments = (options = {}) => {
1377
1431
  });
1378
1432
  }
1379
1433
  }
1380
- })
1434
+ }),
1435
+ options.onMove ? trackPastedComments(options.onMove) : []
1381
1436
  ];
1382
1437
  };
1383
1438
 
@@ -2924,7 +2979,6 @@ export {
2924
2979
  comments,
2925
2980
  createAutomergeModel,
2926
2981
  createYjsModel,
2927
- cursorConverter,
2928
2982
  defaultMarkdownSlots,
2929
2983
  defaultOptions,
2930
2984
  defaultSlots,