@wordinweb/agent 0.2.4 → 0.2.5

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.
@@ -2711,6 +2711,11 @@ function parseParagraph(p, ctx) {
2711
2711
  }
2712
2712
  }
2713
2713
  ensureCaretAnchor(p, para);
2714
+ if (ctx.revisionView === "markup" && pPr) {
2715
+ const markRPr = child(pPr, "rPr");
2716
+ if (markRPr && child(markRPr, "del")) para.markRevision = "del";
2717
+ else if (markRPr && child(markRPr, "ins")) para.markRevision = "ins";
2718
+ }
2714
2719
  return para;
2715
2720
  }
2716
2721
  function hasVisibleContent(c) {
@@ -12057,6 +12062,20 @@ function buildAtoms(doc, para, measurer, fields, fallbackFamily, gridPitch) {
12057
12062
  if (childEl.type === "run") pushRun(childEl);
12058
12063
  else for (const r of childEl.runs) pushRun(r, childEl.href ?? (childEl.anchor ? "#" + childEl.anchor : void 0));
12059
12064
  }
12065
+ if (para.markRevision) {
12066
+ const last = para.children.at(-1);
12067
+ const lastRun = last?.type === "hyperlink" ? last.runs.at(-1) : last;
12068
+ const deleted = para.markRevision === "del";
12069
+ pushRun({
12070
+ type: "run",
12071
+ props: {
12072
+ ...lastRun?.props ?? {},
12073
+ color: deleted ? "#D93025" : "#188038",
12074
+ ...deleted ? { strike: true } : { underline: "single" }
12075
+ },
12076
+ content: [{ kind: "text", text: "\xB6" }]
12077
+ });
12078
+ }
12060
12079
  if (gridPitch) {
12061
12080
  for (let i = 0; i + 1 < atoms.length; i++) {
12062
12081
  const punct = atoms[i];
@@ -20158,8 +20177,32 @@ function mergeParagraphBackward(doc, pEl) {
20158
20177
  const moved = pEl.children.filter((c) => localName(c.name) !== "pPr" && !isPlaceholderRun(c));
20159
20178
  prev.children.push(...moved);
20160
20179
  parent.children.splice(idx, 1);
20180
+ carryMarkRevision(prev, pEl);
20161
20181
  return finishMerge(prev);
20162
20182
  }
20183
+ function carryMarkRevision(survivor, gone) {
20184
+ const markOf = (p) => p.children.find((c) => localName(c.name) === "pPr")?.children.find((c) => localName(c.name) === "rPr");
20185
+ const isRev = (c) => localName(c.name) === "ins" || localName(c.name) === "del";
20186
+ const theirs = markOf(gone)?.children.filter(isRev) ?? [];
20187
+ let pPr = survivor.children.find((c) => localName(c.name) === "pPr");
20188
+ let rPr = markOf(survivor);
20189
+ if (!rPr && theirs.length === 0) return;
20190
+ if (!rPr) {
20191
+ const w = survivor.name.includes(":") ? survivor.name.slice(0, survivor.name.indexOf(":") + 1) : "";
20192
+ if (!pPr) {
20193
+ pPr = { name: `${w}pPr`, attrs: {}, children: [], text: "" };
20194
+ survivor.children.unshift(pPr);
20195
+ }
20196
+ rPr = { name: `${w}rPr`, attrs: {}, children: [], text: "" };
20197
+ const at = pPr.children.findIndex((c) => localName(c.name) === "sectPr" || localName(c.name) === "pPrChange");
20198
+ pPr.children.splice(at === -1 ? pPr.children.length : at, 0, rPr);
20199
+ }
20200
+ rPr.children = [...theirs, ...rPr.children.filter((c) => !isRev(c))];
20201
+ if (rPr.children.length === 0 && pPr) {
20202
+ pPr.children.splice(pPr.children.indexOf(rPr), 1);
20203
+ if (pPr.children.length === 0) survivor.children.splice(survivor.children.indexOf(pPr), 1);
20204
+ }
20205
+ }
20163
20206
  function firstTextOf(pEl) {
20164
20207
  const walk2 = (el26) => {
20165
20208
  for (const c of el26.children) {
@@ -36199,17 +36242,7 @@ var _DocxEditor = class _DocxEditor {
36199
36242
  if (pEl && firstTextOf(pEl) === caret.t) {
36200
36243
  this.host.history?.checkpoint();
36201
36244
  if (this.clearListAtCaret()) return;
36202
- const prev = siblingParagraph(this.host.doc, pEl, -1);
36203
- if (!prev) return;
36204
- const junction = lastTextOf(prev);
36205
- const mergeBlockId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(pEl) : void 0;
36206
- if (mergeParagraphBackward(this.host.doc, pEl)) {
36207
- if (mergeBlockId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeBlockId });
36208
- const target = junction && paragraphOf(this.host.doc, junction) ? junction : caret.t;
36209
- this.caret = { t: target, run: caret.run, offset: target === junction ? target.text.length : 0 };
36210
- invalidateParagraphSignature(paragraphOf(this.host.doc, target) ?? pEl);
36211
- this.commit(false, "local", true);
36212
- }
36245
+ this.mergeIntoPrevious(pEl);
36213
36246
  return;
36214
36247
  }
36215
36248
  if (!this.stepToNeighbor(-1)) return;
@@ -36225,19 +36258,8 @@ var _DocxEditor = class _DocxEditor {
36225
36258
  if (caret.offset >= caret.t.text.length) {
36226
36259
  const pEl = paragraphOf(this.host.doc, caret.t);
36227
36260
  if (pEl && lastTextOf(pEl) === caret.t) {
36228
- const next = siblingParagraph(this.host.doc, pEl, 1);
36229
- if (!next) return;
36230
36261
  this.host.history?.checkpoint();
36231
- const mergeNextId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(next) : void 0;
36232
- if (mergeParagraphBackward(this.host.doc, next)) {
36233
- if (mergeNextId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeNextId });
36234
- if (!paragraphOf(this.host.doc, caret.t)) {
36235
- const t = firstTextOf(next);
36236
- if (t) this.caret = { t, run: caret.run, offset: 0 };
36237
- }
36238
- invalidateParagraphSignature(paragraphOf(this.host.doc, this.caret?.t ?? caret.t) ?? pEl);
36239
- this.commit(false, "local", true);
36240
- }
36262
+ this.mergeNextInto(pEl);
36241
36263
  return;
36242
36264
  }
36243
36265
  if (!this.stepToNeighbor(1)) return;
@@ -36255,6 +36277,44 @@ var _DocxEditor = class _DocxEditor {
36255
36277
  emitDelete(blockId, runId, start, end) {
36256
36278
  if (end > start) this.host.onIntent?.({ kind: "deleteText", blockId, runId, start, end });
36257
36279
  }
36280
+ /** Backspace at the start of `pEl`: merge it into the previous paragraph. */
36281
+ mergeIntoPrevious(pEl) {
36282
+ const caret = this.caret;
36283
+ if (!caret) return;
36284
+ const prev = siblingParagraph(this.host.doc, pEl, -1);
36285
+ if (!prev) return;
36286
+ const junction = lastTextOf(prev);
36287
+ const mergeBlockId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(pEl) : void 0;
36288
+ if (mergeParagraphBackward(this.host.doc, pEl)) {
36289
+ if (mergeBlockId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeBlockId });
36290
+ const target = junction && paragraphOf(this.host.doc, junction) ? junction : caret.t;
36291
+ this.caret = { t: target, run: caret.run, offset: target === junction ? target.text.length : 0 };
36292
+ invalidateParagraphSignature(paragraphOf(this.host.doc, target) ?? pEl);
36293
+ this.commit(false, "local", true);
36294
+ }
36295
+ }
36296
+ /** Delete at the end of `pEl`: merge the next paragraph into it. */
36297
+ mergeNextInto(pEl) {
36298
+ const caret = this.caret;
36299
+ if (!caret) return;
36300
+ const next = siblingParagraph(this.host.doc, pEl, 1);
36301
+ if (!next) return;
36302
+ const mergeNextId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(next) : void 0;
36303
+ if (mergeParagraphBackward(this.host.doc, next)) {
36304
+ if (mergeNextId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeNextId });
36305
+ if (!paragraphOf(this.host.doc, caret.t)) {
36306
+ const t = firstTextOf(next);
36307
+ if (t) this.caret = { t, run: caret.run, offset: 0 };
36308
+ }
36309
+ invalidateParagraphSignature(paragraphOf(this.host.doc, this.caret?.t ?? caret.t) ?? pEl);
36310
+ this.commit(false, "local", true);
36311
+ }
36312
+ }
36313
+ /** True when `pEl`'s paragraph mark is a break this author suggested. */
36314
+ ownSuggestedBreak(pEl) {
36315
+ const mark = paragraphGlyphRevision(pEl, "ins");
36316
+ return !!mark && attr(mark, "author") === this.revisionAuthor;
36317
+ }
36258
36318
  /** Backspace/Delete in suggesting mode: mark one character (or a paragraph
36259
36319
  * mark at a boundary) as a tracked deletion instead of removing it. Skips over
36260
36320
  * text already struck by this author so a repeated press keeps eating real
@@ -36275,6 +36335,10 @@ var _DocxEditor = class _DocxEditor {
36275
36335
  if (this.suggestUnbulletAtCaret()) return;
36276
36336
  const prev = siblingParagraph(doc, pEl, -1);
36277
36337
  if (!prev) return;
36338
+ if (this.ownSuggestedBreak(prev)) {
36339
+ this.mergeIntoPrevious(pEl);
36340
+ return;
36341
+ }
36278
36342
  if (paragraphGlyphRevision(prev, "del")) {
36279
36343
  this.stepToNeighbor(-1);
36280
36344
  this.positionCaret();
@@ -36304,6 +36368,10 @@ var _DocxEditor = class _DocxEditor {
36304
36368
  if (caret.offset >= caret.t.text.length) {
36305
36369
  const pEl = paragraphOf(doc, caret.t);
36306
36370
  if (pEl && lastTextOf(pEl) === caret.t) {
36371
+ if (this.ownSuggestedBreak(pEl)) {
36372
+ this.mergeNextInto(pEl);
36373
+ return;
36374
+ }
36307
36375
  if (paragraphGlyphRevision(pEl, "del")) {
36308
36376
  this.stepToNeighbor(1);
36309
36377
  this.positionCaret();
@@ -45623,4 +45691,4 @@ export {
45623
45691
  AgentDocument,
45624
45692
  collaborativeAgentTarget
45625
45693
  };
45626
- //# sourceMappingURL=chunk-JK7OGOJB.js.map
45694
+ //# sourceMappingURL=chunk-QDZRRLHW.js.map