@arbidocs/coedit 0.4.98 → 0.4.100

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/dist/template.cjs CHANGED
@@ -813,6 +813,59 @@ function fragmentClipboardHtml(fragment, covered = true) {
813
813
  return `<div data-docx-fragment="${btoa(binary)}" data-docx-fragment-end="${covered ? "covered" : "open"}"></div>`;
814
814
  }
815
815
 
816
+ // src/template/track.ts
817
+ var TRACKED = /* @__PURE__ */ new Set(["w:ins", "w:del", "w:moveFrom", "w:moveTo"]);
818
+ function trackInsertion(fragment, revision, covered) {
819
+ const pkg = Pkg.read(fragment);
820
+ const main = pkg.main;
821
+ const root = pkg.xml(main);
822
+ const body = kid(root, "w:body");
823
+ if (!root || !body) return fragment;
824
+ const attrs = { "w:id": "1", "w:author": revision.author, "w:date": revision.date };
825
+ const lastParagraph = body.children.filter(isEl).findLast((c) => c.name === "w:p");
826
+ const visit = (node) => {
827
+ node.children = node.children.map((child) => {
828
+ if (!isEl(child)) return child;
829
+ if (child.name === "w:r") return TRACKED.has(node.name) ? child : el("w:ins", attrs, [child]);
830
+ if (TRACKED.has(child.name)) return child;
831
+ if (child.name === "w:tr") {
832
+ markRow(child, attrs);
833
+ return child;
834
+ }
835
+ visit(child);
836
+ if (child.name === "w:p" && (covered || child !== lastParagraph)) markParagraph(child, attrs);
837
+ return child;
838
+ });
839
+ };
840
+ visit(body);
841
+ pkg.setXml(main, root);
842
+ return pkg.write();
843
+ }
844
+ function markParagraph(p, attrs) {
845
+ let pPr = kid(p, "w:pPr");
846
+ if (!pPr) p.children.unshift(pPr = el("w:pPr"));
847
+ let rPr = kid(pPr, "w:rPr");
848
+ if (!rPr) {
849
+ rPr = el("w:rPr");
850
+ const at = pPr.children.findIndex(
851
+ (c) => isEl(c) && (c.name === "w:sectPr" || c.name === "w:pPrChange")
852
+ );
853
+ pPr.children.splice(at < 0 ? pPr.children.length : at, 0, rPr);
854
+ }
855
+ if (!kid(rPr, "w:ins")) rPr.children.unshift(el("w:ins", attrs));
856
+ }
857
+ function markRow(tr, attrs) {
858
+ let trPr = kid(tr, "w:trPr");
859
+ if (!trPr) {
860
+ trPr = el("w:trPr");
861
+ const after = tr.children.findIndex((c) => isEl(c) && c.name === "w:tblPrEx");
862
+ tr.children.splice(after + 1, 0, trPr);
863
+ }
864
+ if (kid(trPr, "w:ins")) return;
865
+ const at = trPr.children.findIndex((c) => isEl(c) && c.name === "w:trPrChange");
866
+ trPr.children.splice(at < 0 ? trPr.children.length : at, 0, el("w:ins", attrs));
867
+ }
868
+
816
869
  // src/template/divergence.ts
817
870
  var UI_ONLY = /* @__PURE__ */ new Set([
818
871
  "w:uiPriority",
@@ -1569,5 +1622,6 @@ exports.linkedLevelStyles = linkedLevelStyles;
1569
1622
  exports.listBuildingBlocks = listBuildingBlocks;
1570
1623
  exports.newFromTemplate = newFromTemplate;
1571
1624
  exports.styleDivergence = styleDivergence;
1625
+ exports.trackInsertion = trackInsertion;
1572
1626
  //# sourceMappingURL=template.cjs.map
1573
1627
  //# sourceMappingURL=template.cjs.map