node-pptx-templater 2.0.0-alpha.0 → 2.0.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-pptx-templater",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "High-performance, low-level PowerPoint (PPTX) OpenXML template engine for Node.js. Dynamically replace text, insert images, update charts (with Excel workbook data caching), and merge table cells without PowerPoint corruption or Repair Mode prompts.",
5
5
  "main": "./src/index.js",
6
6
  "module": "./src/index.mjs",
@@ -209,4 +209,4 @@
209
209
  "publishConfig": {
210
210
  "access": "public"
211
211
  }
212
- }
212
+ }
@@ -1048,6 +1048,63 @@ class SlideManager {
1048
1048
  })
1049
1049
 
1050
1050
  sldIdLst['p:sldId'] = ordered
1051
+
1052
+ // Synchronize sections order with the new slide order
1053
+ const orderedSlideIds = ordered.map(o => String(o['@_id']))
1054
+ const extLst = this.#xmlParser.getNode(this.#presentationObj, 'p:presentation.p:extLst')
1055
+ if (extLst?.['p:ext']) {
1056
+ const exts = Array.isArray(extLst['p:ext']) ? extLst['p:ext'] : [extLst['p:ext']]
1057
+ for (const ext of exts) {
1058
+ const sectionLst = ext['p14:sectionLst']
1059
+ if (sectionLst?.['p14:section']) {
1060
+ const sections = Array.isArray(sectionLst['p14:section'])
1061
+ ? sectionLst['p14:section']
1062
+ : [sectionLst['p14:section']]
1063
+
1064
+ // 1. Map each slideId to its section name/id (so we can identify its section)
1065
+ const slideToSectionMap = new Map()
1066
+ for (const section of sections) {
1067
+ const sldIdLst = section['p14:sldIdLst']
1068
+ if (sldIdLst?.['p14:sldId']) {
1069
+ const sldIds = Array.isArray(sldIdLst['p14:sldId'])
1070
+ ? sldIdLst['p14:sldId']
1071
+ : [sldIdLst['p14:sldId']]
1072
+ for (const sldId of sldIds) {
1073
+ if (sldId && sldId['@_id']) {
1074
+ slideToSectionMap.set(String(sldId['@_id']), section)
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+
1080
+ // 2. Clear the slide lists of all sections
1081
+ for (const section of sections) {
1082
+ if (!section['p14:sldIdLst']) {
1083
+ section['p14:sldIdLst'] = { 'p14:sldId': [] }
1084
+ } else {
1085
+ section['p14:sldIdLst']['p14:sldId'] = []
1086
+ }
1087
+ }
1088
+
1089
+ // 3. Re-populate the sections in the new slide order
1090
+ for (const slideId of orderedSlideIds) {
1091
+ const section = slideToSectionMap.get(slideId)
1092
+ if (section) {
1093
+ section['p14:sldIdLst']['p14:sldId'].push({ '@_id': slideId })
1094
+ } else if (sections.length > 0) {
1095
+ // Fallback: if a slide has no section (e.g. newly added without section info),
1096
+ // place it in the last section to maintain contiguity.
1097
+ const lastSection = sections[sections.length - 1]
1098
+ if (!lastSection['p14:sldIdLst']) {
1099
+ lastSection['p14:sldIdLst'] = { 'p14:sldId': [] }
1100
+ }
1101
+ lastSection['p14:sldIdLst']['p14:sldId'].push({ '@_id': slideId })
1102
+ }
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+
1051
1108
  this.#flushPresentation()
1052
1109
  }
1053
1110