@adeu/core 1.18.0 → 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 +68 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +68 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/engine.comment-preservation.test.ts +174 -0
- package/src/engine.feedback.test.ts +34 -2
- package/src/engine.ts +106 -30
package/dist/index.cjs
CHANGED
|
@@ -3063,8 +3063,19 @@ var RedlineEngine = class {
|
|
|
3063
3063
|
this.mapper = new DocumentMapper(this.doc);
|
|
3064
3064
|
this.comments_manager = new CommentsManager(this.doc);
|
|
3065
3065
|
}
|
|
3066
|
+
/**
|
|
3067
|
+
* Return a hint when a short, single-token anchor contains punctuation that
|
|
3068
|
+
* can split awkwardly, else null.
|
|
3069
|
+
*
|
|
3070
|
+
* Surface this ONLY for edits that actually failed to match/apply. On a
|
|
3071
|
+
* successful edit the batch report already carries the redline preview, so
|
|
3072
|
+
* emitting this would be a false positive: the punctuation (dates,
|
|
3073
|
+
* `[_name_]` placeholders, `____` blanks) is frequently the literal target
|
|
3074
|
+
* and the edit succeeds despite it. Mirrors the Python engine.
|
|
3075
|
+
*/
|
|
3066
3076
|
_check_punctuation_warning(target_text) {
|
|
3067
3077
|
if (!target_text) return null;
|
|
3078
|
+
if (target_text.length > 20 || target_text.includes(" ")) return null;
|
|
3068
3079
|
if (target_text.includes("_") || target_text.includes("-")) {
|
|
3069
3080
|
return `Warning: target_text '${target_text}' contains tokenization-splitting punctuation ('_' or '-'). This can trigger mid-word splits in the diff engine. Consider using a longer plain-prose anchor.`;
|
|
3070
3081
|
}
|
|
@@ -3862,6 +3873,27 @@ var RedlineEngine = class {
|
|
|
3862
3873
|
ref_run.appendChild(ref);
|
|
3863
3874
|
insertAfter(ref_run, new_end);
|
|
3864
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
|
+
}
|
|
3865
3897
|
_clean_wrapping_comments(element) {
|
|
3866
3898
|
let first_node = element;
|
|
3867
3899
|
while (true) {
|
|
@@ -3926,7 +3958,11 @@ var RedlineEngine = class {
|
|
|
3926
3958
|
for (const s of starts_to_remove) {
|
|
3927
3959
|
const c_id = s.getAttribute("w:id");
|
|
3928
3960
|
if (c_id && end_ids.has(c_id)) {
|
|
3929
|
-
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
|
+
}
|
|
3930
3966
|
if (s.parentNode) s.parentNode.removeChild(s);
|
|
3931
3967
|
for (const e of ends_to_remove) {
|
|
3932
3968
|
let e_id = null;
|
|
@@ -4055,10 +4091,9 @@ var RedlineEngine = class {
|
|
|
4055
4091
|
if (edit.target_text.includes("|")) {
|
|
4056
4092
|
matches = matches.slice(0, 1);
|
|
4057
4093
|
} else {
|
|
4058
|
-
const positions = matches.map(
|
|
4059
|
-
start,
|
|
4060
|
-
|
|
4061
|
-
]);
|
|
4094
|
+
const positions = matches.map(
|
|
4095
|
+
([start, length]) => [start, start + length]
|
|
4096
|
+
);
|
|
4062
4097
|
errors.push(
|
|
4063
4098
|
format_ambiguity_error(
|
|
4064
4099
|
i + 1 + index_offset,
|
|
@@ -4225,7 +4260,10 @@ var RedlineEngine = class {
|
|
|
4225
4260
|
_process_batch_internal(changes, dry_run_mode = false) {
|
|
4226
4261
|
for (const c of changes) {
|
|
4227
4262
|
if (c && typeof c === "object" && c.type === "modify" && c.target_text && c.new_text) {
|
|
4228
|
-
const [strippedTarget, strippedNew] = stripMatchingHeadingHashes(
|
|
4263
|
+
const [strippedTarget, strippedNew] = stripMatchingHeadingHashes(
|
|
4264
|
+
c.target_text,
|
|
4265
|
+
c.new_text
|
|
4266
|
+
);
|
|
4229
4267
|
c.target_text = strippedTarget;
|
|
4230
4268
|
c.new_text = strippedNew;
|
|
4231
4269
|
}
|
|
@@ -4241,10 +4279,7 @@ var RedlineEngine = class {
|
|
|
4241
4279
|
const action_errors = actions.length > 0 ? this.validate_review_actions(actions) : [];
|
|
4242
4280
|
const validate_edits_now = edits.length > 0 && action_errors.length > 0;
|
|
4243
4281
|
const edit_errors = validate_edits_now ? this.validate_edits(edits) : [];
|
|
4244
|
-
const all_errors = [
|
|
4245
|
-
...action_errors,
|
|
4246
|
-
...edit_errors
|
|
4247
|
-
];
|
|
4282
|
+
const all_errors = [...action_errors, ...edit_errors];
|
|
4248
4283
|
if (all_errors.length > 0) {
|
|
4249
4284
|
throw new BatchValidationError(all_errors);
|
|
4250
4285
|
}
|
|
@@ -4281,11 +4316,11 @@ var RedlineEngine = class {
|
|
|
4281
4316
|
for (let i = 0; i < edits.length; i++) {
|
|
4282
4317
|
const edit = edits[i];
|
|
4283
4318
|
const single_errors = this.validate_edits([edit], i);
|
|
4284
|
-
const warning = this._check_punctuation_warning(
|
|
4285
|
-
edit.target_text || ""
|
|
4286
|
-
);
|
|
4287
4319
|
if (single_errors.length > 0) {
|
|
4288
4320
|
skipped_edits++;
|
|
4321
|
+
const warning = this._check_punctuation_warning(
|
|
4322
|
+
edit.target_text || ""
|
|
4323
|
+
);
|
|
4289
4324
|
edits_reports.push({
|
|
4290
4325
|
status: "failed",
|
|
4291
4326
|
target_text: edit.target_text || "",
|
|
@@ -4305,7 +4340,7 @@ var RedlineEngine = class {
|
|
|
4305
4340
|
status: "applied",
|
|
4306
4341
|
target_text: edit.target_text || "",
|
|
4307
4342
|
new_text: edit.new_text || "",
|
|
4308
|
-
warning,
|
|
4343
|
+
warning: null,
|
|
4309
4344
|
error: null,
|
|
4310
4345
|
critic_markup: previews[0],
|
|
4311
4346
|
clean_text: previews[1],
|
|
@@ -4319,6 +4354,9 @@ var RedlineEngine = class {
|
|
|
4319
4354
|
} else {
|
|
4320
4355
|
skipped_edits++;
|
|
4321
4356
|
const error_msg = this.skipped_details.length > 0 ? this.skipped_details[this.skipped_details.length - 1] : "Failed to apply edit";
|
|
4357
|
+
const warning = this._check_punctuation_warning(
|
|
4358
|
+
edit.target_text || ""
|
|
4359
|
+
);
|
|
4322
4360
|
edits_reports.push({
|
|
4323
4361
|
status: "failed",
|
|
4324
4362
|
target_text: edit.target_text || "",
|
|
@@ -4357,22 +4395,22 @@ var RedlineEngine = class {
|
|
|
4357
4395
|
this.clean_mapper = null;
|
|
4358
4396
|
throw err;
|
|
4359
4397
|
}
|
|
4360
|
-
applied_edits = edits.filter(
|
|
4361
|
-
(e) => e._applied_status
|
|
4362
|
-
).length;
|
|
4398
|
+
applied_edits = edits.filter((e) => e._applied_status).length;
|
|
4363
4399
|
skipped_edits = edits.length - applied_edits;
|
|
4364
4400
|
for (const edit of edits) {
|
|
4365
4401
|
const success = edit._applied_status || false;
|
|
4366
4402
|
const error_msg = edit._error_msg || null;
|
|
4367
|
-
const warning = this._check_punctuation_warning(
|
|
4368
|
-
edit.target_text || ""
|
|
4369
|
-
);
|
|
4370
4403
|
let critic_markup = null;
|
|
4371
4404
|
let clean_text = null;
|
|
4405
|
+
let warning = null;
|
|
4372
4406
|
if (success) {
|
|
4373
4407
|
const previews = this._build_edit_context_previews(edit);
|
|
4374
4408
|
critic_markup = previews[0];
|
|
4375
4409
|
clean_text = previews[1];
|
|
4410
|
+
} else {
|
|
4411
|
+
warning = this._check_punctuation_warning(
|
|
4412
|
+
edit.target_text || ""
|
|
4413
|
+
);
|
|
4376
4414
|
}
|
|
4377
4415
|
edits_reports.push({
|
|
4378
4416
|
status: success ? "applied" : "failed",
|
|
@@ -4398,7 +4436,7 @@ var RedlineEngine = class {
|
|
|
4398
4436
|
skipped_details: this.skipped_details,
|
|
4399
4437
|
edits: edits_reports,
|
|
4400
4438
|
engine: "node",
|
|
4401
|
-
version: "1.
|
|
4439
|
+
version: "1.18.2"
|
|
4402
4440
|
};
|
|
4403
4441
|
}
|
|
4404
4442
|
apply_edits(edits, page_offsets = []) {
|
|
@@ -4842,7 +4880,10 @@ var RedlineEngine = class {
|
|
|
4842
4880
|
const t_seg = target_segs[k];
|
|
4843
4881
|
const n_seg = new_segs[k];
|
|
4844
4882
|
if (t_seg !== n_seg) {
|
|
4845
|
-
const [seg_prefix, seg_suffix] = trim_common_context(
|
|
4883
|
+
const [seg_prefix, seg_suffix] = trim_common_context(
|
|
4884
|
+
t_seg,
|
|
4885
|
+
n_seg
|
|
4886
|
+
);
|
|
4846
4887
|
const seg_target = t_seg.substring(
|
|
4847
4888
|
seg_prefix,
|
|
4848
4889
|
t_seg.length - seg_suffix
|
|
@@ -5253,7 +5294,11 @@ var RedlineEngine = class {
|
|
|
5253
5294
|
if (is_inline_first) {
|
|
5254
5295
|
const del_parent = last_del.parentNode;
|
|
5255
5296
|
if (del_parent && del_parent.tagName === "w:ins") {
|
|
5256
|
-
this._insert_and_split_ins(
|
|
5297
|
+
this._insert_and_split_ins(
|
|
5298
|
+
del_parent,
|
|
5299
|
+
last_del,
|
|
5300
|
+
result.first_node
|
|
5301
|
+
);
|
|
5257
5302
|
} else {
|
|
5258
5303
|
insertAfter(result.first_node, last_del);
|
|
5259
5304
|
}
|