n8n-nodes-docx-filler 2.4.0 → 2.4.1

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.
@@ -1156,7 +1156,8 @@ class DocxFillerAI {
1156
1156
  }
1157
1157
  // Si l'IA a fourni des mappings valides, les utiliser
1158
1158
  if (llmMappings.length > 0) {
1159
- // Utiliser les mappings de l'IA
1159
+ // Collecter les modifications avec leurs positions
1160
+ const modifications = [];
1160
1161
  const usedIndices = new Set();
1161
1162
  for (const mapping of llmMappings) {
1162
1163
  if (usedIndices.has(mapping.templateIndex))
@@ -1166,10 +1167,21 @@ class DocxFillerAI {
1166
1167
  continue;
1167
1168
  const oldP = targetParagraph.fullMatch;
1168
1169
  const newP = oldP.replace(/(<w:p[^>]*>)([\s\S]*?)(<\/w:p>)/, `$1<w:r><w:t>${escapeXml(mapping.value)}</w:t></w:r>$3`);
1169
- templateXml = templateXml.replace(oldP, newP);
1170
- filledFields.push(`${mapping.fieldType}: ${mapping.value}`);
1170
+ modifications.push({
1171
+ start: targetParagraph.start,
1172
+ end: targetParagraph.end,
1173
+ newContent: newP,
1174
+ fieldType: mapping.fieldType,
1175
+ value: mapping.value,
1176
+ });
1171
1177
  usedIndices.add(mapping.templateIndex);
1172
1178
  }
1179
+ // Appliquer les modifications en ordre INVERSE (pour éviter les décalages de position)
1180
+ modifications.sort((a, b) => b.start - a.start);
1181
+ for (const mod of modifications) {
1182
+ templateXml = templateXml.slice(0, mod.start) + mod.newContent + templateXml.slice(mod.end);
1183
+ filledFields.push(`${mod.fieldType}: ${mod.value}`);
1184
+ }
1173
1185
  }
1174
1186
  else {
1175
1187
  // Fallback: utiliser la logique standard
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-docx-filler",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "n8n node to automatically fill DOCX documents (French DC1, DC2, AE forms) using AI for semantic understanding and field mapping.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",