wordinweb 0.3.6 → 0.3.7

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.
@@ -4461,6 +4461,11 @@ function parseParagraph(p, ctx) {
4461
4461
  }
4462
4462
  }
4463
4463
  ensureCaretAnchor(p, para);
4464
+ if (ctx.revisionView === "markup" && pPr) {
4465
+ const markRPr = child(pPr, "rPr");
4466
+ if (markRPr && child(markRPr, "del")) para.markRevision = "del";
4467
+ else if (markRPr && child(markRPr, "ins")) para.markRevision = "ins";
4468
+ }
4464
4469
  return para;
4465
4470
  }
4466
4471
  function hasVisibleContent(c) {
@@ -13851,6 +13856,20 @@ function buildAtoms(doc, para, measurer, fields, fallbackFamily, gridPitch) {
13851
13856
  if (childEl.type === "run") pushRun(childEl);
13852
13857
  else for (const r of childEl.runs) pushRun(r, childEl.href ?? (childEl.anchor ? "#" + childEl.anchor : void 0));
13853
13858
  }
13859
+ if (para.markRevision) {
13860
+ const last = para.children.at(-1);
13861
+ const lastRun = last?.type === "hyperlink" ? last.runs.at(-1) : last;
13862
+ const deleted = para.markRevision === "del";
13863
+ pushRun({
13864
+ type: "run",
13865
+ props: {
13866
+ ...lastRun?.props ?? {},
13867
+ color: deleted ? "#D93025" : "#188038",
13868
+ ...deleted ? { strike: true } : { underline: "single" }
13869
+ },
13870
+ content: [{ kind: "text", text: "\xB6" }]
13871
+ });
13872
+ }
13854
13873
  if (gridPitch) {
13855
13874
  for (let i = 0; i + 1 < atoms.length; i++) {
13856
13875
  const punct = atoms[i];
@@ -25102,8 +25121,32 @@ function mergeParagraphBackward(doc, pEl) {
25102
25121
  const moved = pEl.children.filter((c) => localName(c.name) !== "pPr" && !isPlaceholderRun(c));
25103
25122
  prev.children.push(...moved);
25104
25123
  parent.children.splice(idx, 1);
25124
+ carryMarkRevision(prev, pEl);
25105
25125
  return finishMerge(prev);
25106
25126
  }
25127
+ function carryMarkRevision(survivor, gone) {
25128
+ const markOf = (p) => p.children.find((c) => localName(c.name) === "pPr")?.children.find((c) => localName(c.name) === "rPr");
25129
+ const isRev = (c) => localName(c.name) === "ins" || localName(c.name) === "del";
25130
+ const theirs = markOf(gone)?.children.filter(isRev) ?? [];
25131
+ let pPr = survivor.children.find((c) => localName(c.name) === "pPr");
25132
+ let rPr = markOf(survivor);
25133
+ if (!rPr && theirs.length === 0) return;
25134
+ if (!rPr) {
25135
+ const w = survivor.name.includes(":") ? survivor.name.slice(0, survivor.name.indexOf(":") + 1) : "";
25136
+ if (!pPr) {
25137
+ pPr = { name: `${w}pPr`, attrs: {}, children: [], text: "" };
25138
+ survivor.children.unshift(pPr);
25139
+ }
25140
+ rPr = { name: `${w}rPr`, attrs: {}, children: [], text: "" };
25141
+ const at = pPr.children.findIndex((c) => localName(c.name) === "sectPr" || localName(c.name) === "pPrChange");
25142
+ pPr.children.splice(at === -1 ? pPr.children.length : at, 0, rPr);
25143
+ }
25144
+ rPr.children = [...theirs, ...rPr.children.filter((c) => !isRev(c))];
25145
+ if (rPr.children.length === 0 && pPr) {
25146
+ pPr.children.splice(pPr.children.indexOf(rPr), 1);
25147
+ if (pPr.children.length === 0) survivor.children.splice(survivor.children.indexOf(pPr), 1);
25148
+ }
25149
+ }
25107
25150
  function firstTextOf(pEl) {
25108
25151
  const walk2 = (el26) => {
25109
25152
  for (const c of el26.children) {
@@ -42034,17 +42077,7 @@ var _DocxEditor = class _DocxEditor {
42034
42077
  if (pEl && firstTextOf(pEl) === caret.t) {
42035
42078
  this.host.history?.checkpoint();
42036
42079
  if (this.clearListAtCaret()) return;
42037
- const prev = siblingParagraph(this.host.doc, pEl, -1);
42038
- if (!prev) return;
42039
- const junction = lastTextOf(prev);
42040
- const mergeBlockId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(pEl) : void 0;
42041
- if (mergeParagraphBackward(this.host.doc, pEl)) {
42042
- if (mergeBlockId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeBlockId });
42043
- const target = junction && paragraphOf(this.host.doc, junction) ? junction : caret.t;
42044
- this.caret = { t: target, run: caret.run, offset: target === junction ? target.text.length : 0 };
42045
- invalidateParagraphSignature(paragraphOf(this.host.doc, target) ?? pEl);
42046
- this.commit(false, "local", true);
42047
- }
42080
+ this.mergeIntoPrevious(pEl);
42048
42081
  return;
42049
42082
  }
42050
42083
  if (!this.stepToNeighbor(-1)) return;
@@ -42060,19 +42093,8 @@ var _DocxEditor = class _DocxEditor {
42060
42093
  if (caret.offset >= caret.t.text.length) {
42061
42094
  const pEl = paragraphOf(this.host.doc, caret.t);
42062
42095
  if (pEl && lastTextOf(pEl) === caret.t) {
42063
- const next = siblingParagraph(this.host.doc, pEl, 1);
42064
- if (!next) return;
42065
42096
  this.host.history?.checkpoint();
42066
- const mergeNextId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(next) : void 0;
42067
- if (mergeParagraphBackward(this.host.doc, next)) {
42068
- if (mergeNextId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeNextId });
42069
- if (!paragraphOf(this.host.doc, caret.t)) {
42070
- const t = firstTextOf(next);
42071
- if (t) this.caret = { t, run: caret.run, offset: 0 };
42072
- }
42073
- invalidateParagraphSignature(paragraphOf(this.host.doc, this.caret?.t ?? caret.t) ?? pEl);
42074
- this.commit(false, "local", true);
42075
- }
42097
+ this.mergeNextInto(pEl);
42076
42098
  return;
42077
42099
  }
42078
42100
  if (!this.stepToNeighbor(1)) return;
@@ -42090,6 +42112,44 @@ var _DocxEditor = class _DocxEditor {
42090
42112
  emitDelete(blockId, runId, start, end) {
42091
42113
  if (end > start) this.host.onIntent?.({ kind: "deleteText", blockId, runId, start, end });
42092
42114
  }
42115
+ /** Backspace at the start of `pEl`: merge it into the previous paragraph. */
42116
+ mergeIntoPrevious(pEl) {
42117
+ const caret = this.caret;
42118
+ if (!caret) return;
42119
+ const prev = siblingParagraph(this.host.doc, pEl, -1);
42120
+ if (!prev) return;
42121
+ const junction = lastTextOf(prev);
42122
+ const mergeBlockId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(pEl) : void 0;
42123
+ if (mergeParagraphBackward(this.host.doc, pEl)) {
42124
+ if (mergeBlockId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeBlockId });
42125
+ const target = junction && paragraphOf(this.host.doc, junction) ? junction : caret.t;
42126
+ this.caret = { t: target, run: caret.run, offset: target === junction ? target.text.length : 0 };
42127
+ invalidateParagraphSignature(paragraphOf(this.host.doc, target) ?? pEl);
42128
+ this.commit(false, "local", true);
42129
+ }
42130
+ }
42131
+ /** Delete at the end of `pEl`: merge the next paragraph into it. */
42132
+ mergeNextInto(pEl) {
42133
+ const caret = this.caret;
42134
+ if (!caret) return;
42135
+ const next = siblingParagraph(this.host.doc, pEl, 1);
42136
+ if (!next) return;
42137
+ const mergeNextId = this.host.onIntent && this.host.doc.stableIds ? this.host.doc.stableIds.idOf(next) : void 0;
42138
+ if (mergeParagraphBackward(this.host.doc, next)) {
42139
+ if (mergeNextId !== void 0) this.host.onIntent?.({ kind: "mergeParagraph", blockId: mergeNextId });
42140
+ if (!paragraphOf(this.host.doc, caret.t)) {
42141
+ const t = firstTextOf(next);
42142
+ if (t) this.caret = { t, run: caret.run, offset: 0 };
42143
+ }
42144
+ invalidateParagraphSignature(paragraphOf(this.host.doc, this.caret?.t ?? caret.t) ?? pEl);
42145
+ this.commit(false, "local", true);
42146
+ }
42147
+ }
42148
+ /** True when `pEl`'s paragraph mark is a break this author suggested. */
42149
+ ownSuggestedBreak(pEl) {
42150
+ const mark = paragraphGlyphRevision(pEl, "ins");
42151
+ return !!mark && attr(mark, "author") === this.revisionAuthor;
42152
+ }
42093
42153
  /** Backspace/Delete in suggesting mode: mark one character (or a paragraph
42094
42154
  * mark at a boundary) as a tracked deletion instead of removing it. Skips over
42095
42155
  * text already struck by this author so a repeated press keeps eating real
@@ -42110,6 +42170,10 @@ var _DocxEditor = class _DocxEditor {
42110
42170
  if (this.suggestUnbulletAtCaret()) return;
42111
42171
  const prev = siblingParagraph(doc, pEl, -1);
42112
42172
  if (!prev) return;
42173
+ if (this.ownSuggestedBreak(prev)) {
42174
+ this.mergeIntoPrevious(pEl);
42175
+ return;
42176
+ }
42113
42177
  if (paragraphGlyphRevision(prev, "del")) {
42114
42178
  this.stepToNeighbor(-1);
42115
42179
  this.positionCaret();
@@ -42139,6 +42203,10 @@ var _DocxEditor = class _DocxEditor {
42139
42203
  if (caret.offset >= caret.t.text.length) {
42140
42204
  const pEl = paragraphOf(doc, caret.t);
42141
42205
  if (pEl && lastTextOf(pEl) === caret.t) {
42206
+ if (this.ownSuggestedBreak(pEl)) {
42207
+ this.mergeNextInto(pEl);
42208
+ return;
42209
+ }
42142
42210
  if (paragraphGlyphRevision(pEl, "del")) {
42143
42211
  this.stepToNeighbor(1);
42144
42212
  this.positionCaret();
@@ -56575,4 +56643,4 @@ export {
56575
56643
  cfb/cfb.js:
56576
56644
  (*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
56577
56645
  */
56578
- //# sourceMappingURL=chunk-WPQ6GPG4.js.map
56646
+ //# sourceMappingURL=chunk-ULPL55MT.js.map