@adeu/core 1.18.1 → 1.18.2
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/index.cjs +45 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +45 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/engine.comment-preservation.test.ts +174 -0
- package/src/engine.ts +76 -23
package/dist/index.cjs
CHANGED
|
@@ -3873,6 +3873,27 @@ var RedlineEngine = class {
|
|
|
3873
3873
|
ref_run.appendChild(ref);
|
|
3874
3874
|
insertAfter(ref_run, new_end);
|
|
3875
3875
|
}
|
|
3876
|
+
/**
|
|
3877
|
+
* Read a comment's author directly from the comments part. Used by
|
|
3878
|
+
* _clean_wrapping_comments to decide whether a wrapping comment belongs to
|
|
3879
|
+
* another author (and must be preserved when its anchored change is
|
|
3880
|
+
* accepted/rejected) or to us (safe to delete). Reads the part rather than
|
|
3881
|
+
* the mapper because the mapper's comments_map is not rebuilt between review
|
|
3882
|
+
* actions, so it can be stale mid-batch. Returns null if not found.
|
|
3883
|
+
*/
|
|
3884
|
+
_get_comment_author(c_id) {
|
|
3885
|
+
const part = this.doc.pkg.parts.find(
|
|
3886
|
+
(p) => p.contentType === "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"
|
|
3887
|
+
);
|
|
3888
|
+
if (!part) return null;
|
|
3889
|
+
const comments = findAllDescendants(part._element, "w:comment");
|
|
3890
|
+
for (const c of comments) {
|
|
3891
|
+
if (c.getAttribute("w:id") === c_id) {
|
|
3892
|
+
return c.getAttribute("w:author");
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
return null;
|
|
3896
|
+
}
|
|
3876
3897
|
_clean_wrapping_comments(element) {
|
|
3877
3898
|
let first_node = element;
|
|
3878
3899
|
while (true) {
|
|
@@ -3937,7 +3958,11 @@ var RedlineEngine = class {
|
|
|
3937
3958
|
for (const s of starts_to_remove) {
|
|
3938
3959
|
const c_id = s.getAttribute("w:id");
|
|
3939
3960
|
if (c_id && end_ids.has(c_id)) {
|
|
3940
|
-
this.
|
|
3961
|
+
const author = this._get_comment_author(c_id);
|
|
3962
|
+
const is_own = author !== null && author === this.author;
|
|
3963
|
+
if (is_own) {
|
|
3964
|
+
this.comments_manager.deleteComment(c_id);
|
|
3965
|
+
}
|
|
3941
3966
|
if (s.parentNode) s.parentNode.removeChild(s);
|
|
3942
3967
|
for (const e of ends_to_remove) {
|
|
3943
3968
|
let e_id = null;
|
|
@@ -4066,10 +4091,9 @@ var RedlineEngine = class {
|
|
|
4066
4091
|
if (edit.target_text.includes("|")) {
|
|
4067
4092
|
matches = matches.slice(0, 1);
|
|
4068
4093
|
} else {
|
|
4069
|
-
const positions = matches.map(
|
|
4070
|
-
start,
|
|
4071
|
-
|
|
4072
|
-
]);
|
|
4094
|
+
const positions = matches.map(
|
|
4095
|
+
([start, length]) => [start, start + length]
|
|
4096
|
+
);
|
|
4073
4097
|
errors.push(
|
|
4074
4098
|
format_ambiguity_error(
|
|
4075
4099
|
i + 1 + index_offset,
|
|
@@ -4236,7 +4260,10 @@ var RedlineEngine = class {
|
|
|
4236
4260
|
_process_batch_internal(changes, dry_run_mode = false) {
|
|
4237
4261
|
for (const c of changes) {
|
|
4238
4262
|
if (c && typeof c === "object" && c.type === "modify" && c.target_text && c.new_text) {
|
|
4239
|
-
const [strippedTarget, strippedNew] = stripMatchingHeadingHashes(
|
|
4263
|
+
const [strippedTarget, strippedNew] = stripMatchingHeadingHashes(
|
|
4264
|
+
c.target_text,
|
|
4265
|
+
c.new_text
|
|
4266
|
+
);
|
|
4240
4267
|
c.target_text = strippedTarget;
|
|
4241
4268
|
c.new_text = strippedNew;
|
|
4242
4269
|
}
|
|
@@ -4252,10 +4279,7 @@ var RedlineEngine = class {
|
|
|
4252
4279
|
const action_errors = actions.length > 0 ? this.validate_review_actions(actions) : [];
|
|
4253
4280
|
const validate_edits_now = edits.length > 0 && action_errors.length > 0;
|
|
4254
4281
|
const edit_errors = validate_edits_now ? this.validate_edits(edits) : [];
|
|
4255
|
-
const all_errors = [
|
|
4256
|
-
...action_errors,
|
|
4257
|
-
...edit_errors
|
|
4258
|
-
];
|
|
4282
|
+
const all_errors = [...action_errors, ...edit_errors];
|
|
4259
4283
|
if (all_errors.length > 0) {
|
|
4260
4284
|
throw new BatchValidationError(all_errors);
|
|
4261
4285
|
}
|
|
@@ -4371,9 +4395,7 @@ var RedlineEngine = class {
|
|
|
4371
4395
|
this.clean_mapper = null;
|
|
4372
4396
|
throw err;
|
|
4373
4397
|
}
|
|
4374
|
-
applied_edits = edits.filter(
|
|
4375
|
-
(e) => e._applied_status
|
|
4376
|
-
).length;
|
|
4398
|
+
applied_edits = edits.filter((e) => e._applied_status).length;
|
|
4377
4399
|
skipped_edits = edits.length - applied_edits;
|
|
4378
4400
|
for (const edit of edits) {
|
|
4379
4401
|
const success = edit._applied_status || false;
|
|
@@ -4414,7 +4436,7 @@ var RedlineEngine = class {
|
|
|
4414
4436
|
skipped_details: this.skipped_details,
|
|
4415
4437
|
edits: edits_reports,
|
|
4416
4438
|
engine: "node",
|
|
4417
|
-
version: "1.
|
|
4439
|
+
version: "1.18.2"
|
|
4418
4440
|
};
|
|
4419
4441
|
}
|
|
4420
4442
|
apply_edits(edits, page_offsets = []) {
|
|
@@ -4858,7 +4880,10 @@ var RedlineEngine = class {
|
|
|
4858
4880
|
const t_seg = target_segs[k];
|
|
4859
4881
|
const n_seg = new_segs[k];
|
|
4860
4882
|
if (t_seg !== n_seg) {
|
|
4861
|
-
const [seg_prefix, seg_suffix] = trim_common_context(
|
|
4883
|
+
const [seg_prefix, seg_suffix] = trim_common_context(
|
|
4884
|
+
t_seg,
|
|
4885
|
+
n_seg
|
|
4886
|
+
);
|
|
4862
4887
|
const seg_target = t_seg.substring(
|
|
4863
4888
|
seg_prefix,
|
|
4864
4889
|
t_seg.length - seg_suffix
|
|
@@ -5269,7 +5294,11 @@ var RedlineEngine = class {
|
|
|
5269
5294
|
if (is_inline_first) {
|
|
5270
5295
|
const del_parent = last_del.parentNode;
|
|
5271
5296
|
if (del_parent && del_parent.tagName === "w:ins") {
|
|
5272
|
-
this._insert_and_split_ins(
|
|
5297
|
+
this._insert_and_split_ins(
|
|
5298
|
+
del_parent,
|
|
5299
|
+
last_del,
|
|
5300
|
+
result.first_node
|
|
5301
|
+
);
|
|
5273
5302
|
} else {
|
|
5274
5303
|
insertAfter(result.first_node, last_del);
|
|
5275
5304
|
}
|