From 91334ab3a9cfc4ec02140762eb7dceffa7465e8a Mon Sep 17 00:00:00 2001 From: Mike Meerschaert Date: Tue, 9 Aug 2022 09:16:12 -0700 Subject: [PATCH 1/3] solution for issue #625 --- demos/modules/demo_table.mjs | 4 +++- demos/modules/masters.mjs | 18 ++++++++++++++++++ src/gen-objects.ts | 9 ++++++++- src/slide.ts | 8 +++++++- types/index.d.ts | 4 ++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/demos/modules/demo_table.mjs b/demos/modules/demo_table.mjs index a3942386e..a8f7cbdc7 100644 --- a/demos/modules/demo_table.mjs +++ b/demos/modules/demo_table.mjs @@ -594,7 +594,7 @@ function genSlide07(pptx) { // EX-3: "Master Page with Auto-Paging" { - slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_PLAIN" }); + slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER" }); slide.addText( [ { text: "Table Examples: ", options: DEMO_TITLE_TEXT }, @@ -602,7 +602,9 @@ function genSlide07(pptx) { ], { x: 0.5, y: 0.13, w: "90%" } ); + slide.addText("Auto-Paging table", { placeholder: "footer" }); slide.addTable(arrRows, { x: 1.0, y: 0.6, colW: [0.75, 1.75, 7], margin: 0.05, border: { color: "CFCFCF" }, autoPage: true }); + slide.newAutoPagedSlides.forEach((slide) => slide.addText("Auto-Paging table continued...", { placeholder: "footer" })); } // EX-4: "Auto-Paging Disabled" diff --git a/demos/modules/masters.mjs b/demos/modules/masters.mjs index 164a90834..e2c4d6e34 100644 --- a/demos/modules/masters.mjs +++ b/demos/modules/masters.mjs @@ -62,6 +62,24 @@ export function createMasterSlides(pptx) { slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" }, }); + // MASTER_AUTO_PAGE_TABLE_PLACEHOLDER + pptx.defineSlideMaster({ + title: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER", + background: { fill: "F1F1F1" }, + margin: [0.5, 0.25, 1.0, 0.25], + objects: [ + { rect: { x: 0.0, y: 6.9, w: "100%", h: 0.6, fill: { color: "003b75" } } }, + { image: { x: 11.45, y: 5.95, w: 1.67, h: 0.75, data: STARLABS_LOGO_SM } }, + { + placeholder: { + options: { name: "footer", x: 0, y: 6.9, w: "100%", h: 0.6, align: "center", valign: "middle", color: "FFFFFF", fontSize: 12 }, + text: "(footer placeholder)", + }, + }, + ], + slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" }, + }); + // MASTER_SLIDE (MASTER_PLACEHOLDER) pptx.defineSlideMaster({ title: "MASTER_SLIDE", diff --git a/src/gen-objects.ts b/src/gen-objects.ts index 96499c2a8..c53f51df3 100644 --- a/src/gen-objects.ts +++ b/src/gen-objects.ts @@ -726,7 +726,7 @@ export function addTableDefinition( presLayout: PresLayout, addSlide: Function, getSlide: Function -) { +): PresSlide[] { let slides: PresSlide[] = [target] // Create array of Slides as more may be added by auto-paging let opt: TableProps = options && typeof options === 'object' ? options : {} opt.objectName = opt.objectName ? encodeXmlEntities(opt.objectName) : `Table ${target._slideObjects.filter(obj => obj._type === SLIDE_OBJECT_TYPES.table).length}` @@ -933,6 +933,9 @@ export function addTableDefinition( }) }) + // If autoPage = true, we need to return references to newly created slides if any + const newAutoPagedSlides: PresSlide[] = [] + // STEP 6: Auto-Paging: (via {options} and used internally) // (used internally by `tableToSlides()` to not engage recursion - we've already paged the table data, just add this one) if (opt && opt.autoPage === false) { @@ -967,9 +970,13 @@ export function addTableDefinition( // Add rows to new slide newSlide.addTable(slide.rows, Object.assign({}, opt)) + + // Add reference to the new slide so it can be returned, but don't add the first one because the user already has a reference to that one. + if (idx > 0) newAutoPagedSlides.push(newSlide) } }) } + return newAutoPagedSlides } /** diff --git a/src/slide.ts b/src/slide.ts index e4ecef1ce..f852d9d23 100644 --- a/src/slide.ts +++ b/src/slide.ts @@ -23,6 +23,7 @@ import { MediaProps, ShapeProps, TableRow, + PresSlide, } from './core-interfaces' import * as genObj from './gen-objects' @@ -42,6 +43,7 @@ export default class Slide { public _slideNum: number public _slideNumberProps: SlideNumberProps public _slideObjects: ISlideObject[] + public _newAutoPagedSlides: PresSlide[] constructor(params: { addSlide: Function @@ -144,6 +146,10 @@ export default class Slide { return this._slideNumberProps } + public get newAutoPagedSlides(): PresSlide[] { + return this._newAutoPagedSlides + } + /** * Add chart to Slide * @param {CHART_NAME|IChartMulti[]} type - chart type @@ -215,7 +221,7 @@ export default class Slide { */ addTable(tableRows: TableRow[], options?: TableProps): Slide { // FUTURE: we pass `this` - we dont need to pass layouts - they can be read from this! - genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide) + this._newAutoPagedSlides = genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide) return this } diff --git a/types/index.d.ts b/types/index.d.ts index a49c082e4..8f3066cc0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2505,6 +2505,10 @@ declare namespace PptxGenJS { * Slide number options */ slideNumber: SlideNumberProps + /** + * New slides added by an auto paged table + */ + newAutoPagedSlides: PresSlide[] /** * Add chart to Slide * @param {CHART_NAME|IChartMulti[]} type - chart type From b4cbb3faddc1c4c1185c299ebd63221fa45ec236 Mon Sep 17 00:00:00 2001 From: Brent Ely Date: Tue, 7 Feb 2023 23:57:20 -0600 Subject: [PATCH 2/3] added comments --- demos/modules/demo_table.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demos/modules/demo_table.mjs b/demos/modules/demo_table.mjs index a8f7cbdc7..5943100d5 100644 --- a/demos/modules/demo_table.mjs +++ b/demos/modules/demo_table.mjs @@ -3,8 +3,8 @@ * AUTH: Brent Ely (https://github.com/gitbrent/) * DESC: Common test/demo slides for all library features * DEPS: Used by various demos (./demos/browser, ./demos/node, etc.) - * VER.: 3.10.0 - * BLD.: 20220220 + * VER.: 3.12.0 + * BLD.: 20230207 */ import { @@ -604,6 +604,8 @@ function genSlide07(pptx) { ); slide.addText("Auto-Paging table", { placeholder: "footer" }); slide.addTable(arrRows, { x: 1.0, y: 0.6, colW: [0.75, 1.75, 7], margin: 0.05, border: { color: "CFCFCF" }, autoPage: true }); + // HOWTO: In cases where you want to add custom text, placeholders, etc. to slidemasters, a reference to these slide(s) is needed + // HOWTO: Use the `newAutoPagedSlides` to access references (see [Issue #625](https://github.com/gitbrent/PptxGenJS/issues/625)) slide.newAutoPagedSlides.forEach((slide) => slide.addText("Auto-Paging table continued...", { placeholder: "footer" })); } From 910c43098a1f3a44f1f0dbcf0030a98fc6bc5f7c Mon Sep 17 00:00:00 2001 From: Brent Ely Date: Tue, 7 Feb 2023 23:57:28 -0600 Subject: [PATCH 3/3] updated version --- src/pptxgen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pptxgen.ts b/src/pptxgen.ts index 23bf0e6a4..5cdd84227 100644 --- a/src/pptxgen.ts +++ b/src/pptxgen.ts @@ -97,7 +97,7 @@ import * as genMedia from './gen-media' import * as genTable from './gen-tables' import * as genXml from './gen-xml' -const VERSION = '3.12.0-beta-20230207-2320' +const VERSION = '3.12.0-beta-20230207-2340' export default class PptxGenJS implements IPresentationProps { // Property getters/setters